<?php

class class_menu
{
	//Khai bao bien
		
	var $dbObj;
	var $dbcon;
	var $table_menu;
	var $title;
	var $menu_left_rootid;
	var $menu_bar_rootid;
	var $menu_right_rootid;
	var $lang_id;
	
	function class_menu()
	{
		global $dbconn, $langid, $arr_menu_id;
		//Khoi tao bien
		$this->dbcon = $dbconn;
		$this->dbObj = new my_db();
		$this->table_menu = "contents";
		$this->title = "";
		$this->menu_left_rootid = 0;
		
		if($langid == "" || !isset($langid)) $langid = "0";
		$this->lang_id = $langid;
	}
	
	function CheckSubMenu($catid)
	{		
		$result = 0;
		$sql = "select * from ".$this->table_menu." where cat_parent = $catid";
		$rs = mysql_query($sql);
		//echo $sql;
		if($rs) {
			if(mysql_num_rows($rs)>0) {
				$result = 1;
			}else{
				$result = 0;
			}
		}
		return $result;	
	}//end function CheckSubMenu ==========================
	
	function GetSubMenu_Column($parent_id, $file_link="")
	{
		global $catid;
		$this->title = "";
		if ($file_link == ""){
			$file_link = "index.php";
		}
		
		$td_width = "12";
		$title = "";
		$img_bullet = "../images/bullet/ovuong.gif";
		$td_bullet = "<td width='$td_width' align='center' valign='top' class='menuleft_sub'><font color=#ffffff>-</font></td>";
		$td_line = "<TD height=1 bgcolor=#ffffff colspan='2'></TD>";
		$tr_line = "<TR>$td_line</TR>";
		
		
		//===========================================================================
		//Left Menu 
		$list_left = "<TABLE width='100%' border=0 cellPadding=0 cellSpacing=0 align='right'>";
			
		$list_content_nolink = "
			
			<TR>
			$td_bullet
			<TD height=20 align='left' class='menuleft_sub'>@cat_name@</TD>
			</TR>
		";
			
		$list_content_link = "
			
			<TR>
			 $td_bullet				
			 <TD width='92%' height=20 align='left' class='menuleft_sub'>
			 <A  href='$file_link?catid=@catid@&langid=@langid@' class='menuleft_sub_link'>@cat_name@</A>
			</TD>
			</TR>
		";
		
		$list_content_menulink = "
			
			<TR> 
			$td_bullet								
			 <TD height=20 align='left' class='menuleft_sub'>
			 <A  href='@menu_link@' class='menuleft_sub_link'>@cat_name@</A>
			</TD>
			</TR>
		";
		
		
		$sql_list="SELECT * FROM cat WHERE enable=1 and cat_parent='$parent_id' order by cat_order";
		
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{
			if ($i > 0 && $i < $num_row){
				$line = $tr_line;
			}else{
				$line = "";
			}
			$fld_id = $stmt->row["catid"];
			//echo "fld_id: $fld_id<br>";
			$menu_link = $stmt->row["cat_menu"];
			if ($catid == $fld_id)
			{
				$content=$line.$list_content_nolink;
				$this->title = $stmt->row["cat_name"];
				//echo "catid: $fld_id title: $this->title<br>";
			}
			else
			{				
				if ($menu_link != "" || $menu_link != NULL){
					$content = $line.$list_content_menulink;
				}
				else{
					$content = $line.$list_content_link; 	
				}		
			}
		
			$content=ereg_replace("@catid@",$stmt->row["catid"],$content);
			$content=ereg_replace("@cat_name@",$stmt->row["cat_name"],$content);
		
			$content=ereg_replace("@menuid@",$stmt->row["catid"],$content);
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			
			$content=ereg_replace("@langid@",$this->lang_id,$content);
			
			//print "result:<br><pre>".htmlspecialchars($content, ENT_QUOTES)."</pre>"; //debug
			
			$list_left.= $content;
			$i++;
		}
		
		$list_left.= "   
		</TABLE>";
		
		
		$list_menu = $list_left;
		
		return $list_menu;
		
	}//end function GetSubMenu_Column ===============================



	function GetSubMenu_Column_Hover($parent_id, $file_link="", $css_link="")
	{
		global $catid;
		$this->title = "";
		if ($file_link == ""){
			$file_link = "index.php";
		}
		if($css_link == ""){
			$css_link = "menu_left";
		}
		$css_nolink = $css_link."_nolink";
		
		
		$td_width = "12";
		$title = "";
		$img_bullet = "../images/bullet/ovuong.gif";
		//$td_bullet = "<td width='$td_width' align='center' valign='top' class='menuleft_sub'><font color=#ffffff>-</font></td>";
		$td_bullet = "";
		$td_line = "<TD height=1 bgcolor=#9FDB9F colspan='2' onMouseOver=\"window.hideActiveMenus();\"></TD>";
		$tr_line = "<TR>$td_line</TR>";
		
		
		//===========================================================================
		//Left Menu 
		$list_left = '<TABLE width="96%" border=0 cellpadding="0" cellspacing="0"  align="left" bgcolor="#d2faad"> ';
			
		$list_content_nolink = "
			
			<TR>
			$td_bullet
			<TD height=20 align='left' class='$css_nolink'>@cat_name@</TD>
			</TR>
		";
		$list_content_link_nosubmenu = "			
			<TR>
			 $td_bullet				
			 <TD width='92%' height=20 align='left' class='menuleft_sub'>
			 <A  href='$file_link?catid=@catid@&langid=@langid@' class='$css_link'>@cat_name@</A>
			</TD>
			</TR>
		";		
		$list_content_link = "			
			<TR>
			 $td_bullet				
			 <TD width='92%' height=20 align='left' class='menuleft_sub'>
			 <a class=\"$css_link\" href=\"javascript://\" onMouseOver=\"window.showMenu(window.myMenu@catid@);\">@cat_name@</a>
			</TD>
			</TR>
		";
		
		$list_content_menulink = "
			
			<TR> 
			$td_bullet								
			 <TD height=20 align='left' class='menuleft_sub'>
			 <A  href='@menu_link@' @target@ class='$css_link'>@cat_name@</A>
			</TD>
			</TR>
		";
		
		
		$sql_list="SELECT * FROM cat WHERE enable=1 and cat_parent=$parent_id order by cat_order";	
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{
			if ($i > 0 && $i < $num_row){
				$line = $tr_line;
			}else{
				$line = "";
			}
			$fld_id = $stmt->row["catid"];
			//echo "fld_id: $fld_id<br>";
			$menu_link = $stmt->row["cat_menu"];
			$target = $stmt->row["cat_pic1"];
			//echo "target: $target<br>";
			if($target == "_blank") {
				$target="target='_blank'";
			}else{
				$target="";
			}			

			if ($catid == $fld_id)
			{
				$content=$line.$list_content_nolink;
				$this->title = $stmt->row["cat_name"];
				//echo "catid: $fld_id title: $this->title<br>";
			}
			else
			{		
				$submenu_no = get_values("SELECT count(*) as tong FROM cat where cat_parent='$fld_id'");
		
				if ($submenu_no == 0) //Khong co submenu
				{		
					if ($menu_link != "" || $menu_link != NULL){
						$content=$line.$list_content_menulink;
					}
					else{
						$content=$line.$list_content_link_nosubmenu; //template khong co submenu	
					}
				}
				else 
				{
					$content=$line.$list_content_link;
					//echo "co submenu<br>";
					//echo "<pre>$content</pre>";	
				}						
			
			}
		
			$content=ereg_replace("@catid@",$stmt->row["catid"],$content);
			$content=ereg_replace("@cat_name@",$stmt->row["cat_name"],$content);
		
			$content=ereg_replace("@menuid@",$stmt->row["catid"],$content);
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			$content=ereg_replace("@target@",$target,$content);
			
			$content=ereg_replace("@langid@",$this->lang_id,$content);
			
			//print "result:<br><pre>".htmlspecialchars($content, ENT_QUOTES)."</pre>"; //debug
			
			$list_left.= $content;
			$i++;
		}
		
		$list_left.= "   
		</TABLE>";
		
		
		$list_menu = $list_left;
		
		return $list_menu;
		
	}//end function GetSubMenu_Column_Hover =========================

	function WriteMenuBar_Sub($rootid)
	{
		global $catid;
		
		$list_menu_all = "";
		$list_menu = "";
		
		$temp_list_begin = "\n\n\t var menu@top_parent@ = new Array(); \n";
		$temp_list_link = "\t menu@top_parent@[@stt@]='<a href=\"@file_link@?catid=@catid@&subcatid=@subcatid@&loaitinid=@loaitinid@&langid=@langid@\">@cat_name@</a>'; \n";
		$temp_list_link_menulink = "\t menu@top_parent@[@stt@]='<a href=\"@menu_link@\">@cat_name@</a>'; \n";
		$temp_list_link_menulink_blank = "\t menu@top_parent@[@stt@]='<a href=\"@menu_link@\" target=_blank>@cat_name@</a>'; \n";
		
		//========================== Lap trinh tai day ================
	
	
		//echo "$list_menuleft_id<br>";
		$sql_all = "SELECT * FROM contents WHERE contents_parent = '".$rootid."' order by contents_order";
		//echo "sql_all: $sql_all<br>";
		$stmt_all= new db_query($this->dbcon,$sql_all);
		
		while ($stmt_all->getrow())
		{			
			//Bat dau vong lap, se lay cac top_parent ===========================================
			$top_parent = $stmt_all->row["contents_id"];
			//echo "top_parent:$top_parent<br>";
			
			$sql_parent_num = "SELECT count(*) as tong FROM contents where contents_parent='$top_parent'";
			//echo "sql_parent_num:$sql_parent_num<br>";
			$top_parent_num = get_values($sql_parent_num);
			
			$sql_list="SELECT * FROM contents WHERE contents_parent='$top_parent' order by contents_order ";
			//echo "sql_list: $sql_list<br>";
			$stmt= new db_query($this->dbcon,$sql_list);
			$stt=0;
			while ($stmt->getrow())
			{
				//Vong lap con ===============================================
				//============================================================
				//echo "Vong lap con<br>";
				$fld_id = $stmt->row["contents_id"];
				$loaitinid = $stmt->row["loaitin_id"];
				$menu_link = $stmt->row["contents_url"];				
				$cat_type = $stmt->row["cat_type"];
				$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
				$file_link = get_values($sql_cat_type);	
				//echo "sql_cat_type: $sql_cat_type : $file_link<br>";				
				$target = $stmt->row["target"];
				//echo "target: $target<br>";
				if($target != "") {
					$target="target='$target'";
				}else{
					$target="";
				}					
				
				if ($catid == $fld_id)
				{
					$this->title = $stmt->row["contents_name"];
					
					if($target != ""){
						//echo "target: $target<br>";
						$content=$temp_list_link_menulink_blank; //Link target = _blank
					}else{
						$content=$temp_list_link; 
					}
				}
				else
				{
							
					//Khoi tao bien Menu
					$list_menu_begin = $temp_list_begin;
					$list_menu_begin = ereg_replace("@top_parent@",$top_parent,$list_menu_begin);
					//style
					$list_menu_end = $temp_list_style;
					$list_menu_end = ereg_replace("@top_parent@",$top_parent,$list_menu_end);
										
					//Kiem tra xem co submenu khong	
					if ($submenu_no == 0) //Khong co submenu
					{
						//echo "Khong co submenu: $fld_id<br>";//debug		
						if($target != ""){
							//echo "target: $target<br>";
							$content=$temp_list_link_menulink_blank; //template khong co submenu - Link target = _blank
						}else{
							$content=$temp_list_link; //template khong co submenu
						}						
						//echo "<pre>$content</pre>";		
					}
				}
				
				//$content=$temp_list_link;
				$content=ereg_replace("@subcatid@",$stmt->row["contents_id"],$content);
				
				$content=ereg_replace("@catid@", "$top_parent",$content);
				$content=ereg_replace("@cat_name@",$stmt->row["contents_name"],$content);
				$content=ereg_replace("@cat_parent@",$stmt->row["contents_id"],$content);
				$content=ereg_replace("@top_parent@",$top_parent,$content);
				
				$content=ereg_replace("@menu_link@",$menu_link,$content);
				$content=ereg_replace("@file_link@",$file_link,$content);
				$content=ereg_replace("@loaitinid@", "$loaitinid",$content);
				$content=ereg_replace("@langid@",$this->lang_id."",$content);
				
				$content=ereg_replace("@stt@", "$stt",$content);
				
				
				$list_menu.= $content;
				$stt++;
			}//het while lay catid
			
			$list_menu = $list_menu_begin.$list_menu.$list_menu_end.$list_menu_write;
			$list_menu_all.=$list_submenu.$list_menu;
			
			//echo "<b>list_menu $top_parent</b>:<br><pre>$list_menu</pre>";
			
			//Khoi tao
			$list_menu_begin="";
			$list_menu_end="";
			$list_menu_write="";
			$list_submenu="";
			$list_menu="";
			
		
		} //Het vong lap lay top_parent
		$list_menu_all.="//hello";
		//echo "<b>Ketqua</b>:<br><pre>$list_menu_all</pre>";	

		return $list_menu_all;
	
	}//end function WriteMenu Bar=============================

	function WriteMenuLeft_Sub($root_id = 0)
	{
		global $catid, $subcatid, $langid;
		
		$list_menu_all = "";
		$list_menu = "";
		
		$temp_list_begin = "\n\n\t window.myMenu@top_parent@ = new Menu(); \n";
		//$temp_list_link = "\t myMenu@top_parent@.addMenuItem(\"@cat_name@\", \"top.window.location='@file_link@?catid=@catid@&subcatid=@subcatid@&langid=@langid@'\"); \n";
		//$temp_list_link_menulink = "\t myMenu@top_parent@.addMenuItem(\"@cat_name@\", \"top.window.location='@menu_link@'\"); \n";		
		$temp_list_link = "\t myMenu@top_parent@.addMenuItem(\"@cat_name@\", \"document.location='@file_link@?catid=@catid@&subcatid=@subcatid@&langid=@langid@'\"); \n";
		$temp_list_link_menulink = "\t myMenu@top_parent@.addMenuItem(\"@cat_name@\", \"document.location='@menu_link@'\"); \n";		

		$temp_list_link_menulink_blank = "\t myMenu@top_parent@.addMenuItem(\"@cat_name@\", \"window.open('@menu_link@','MenuLink_@catid@','')\"); \n";		
		
		
		
		$temp_list_style = "
		\t //Thuoc tinh myMenu@top_parent@
		\t myMenu@top_parent@.menuItemBgColor = \"@menuItemBgColor@\";
		\t myMenu@top_parent@.menuHiliteBgColor = \"@menuHiliteBgColor@\";
		\t myMenu@top_parent@.fontColor = \"@fontColor@\";
		\t myMenu@top_parent@.bgColor = \"@bgColor@\";
		";
		$temp_list_write = "
		\t //xuat menu myMenu@top_parent@
		\t myMenu@top_parent@.writeMenus();	
		";
		
		$temp_submenu_begin = "\n\n\t window.mySubMenu@cat_parent@ = new Menu(\"@cat_name@\"); \n";
		$temp_submenu_list_link = "\t mySubMenu@cat_parent@.addMenuItem(\"@cat_name@\", \"top.window.location='@file_link@?catid=0&subcatid=@subcatid@&langid=@langid@'\"); \n";
		$temp_submenu_style = "
		\t //Thuoc tinh mySubMenu@cat_parent@
		\t mySubMenu@cat_parent@.menuItemBgColor = \"@menuItemBgColor@\";
		\t mySubMenu@cat_parent@.menuHiliteBgColor = \"@menuHiliteBgColor@\";
		\t mySubMenu@cat_parent@.fontColor = \"@fontColor@\";
		\t mySubMenu@cat_parent@.bgColor = \"@bgColor@\";
		";
		$temp_submenu = "\t myMenu@top_parent@.addMenuItem(mySubMenu@cat_parent@); \n";	
		
		//========================== Lap trinh tai day ================
		//=============================================================
		
		//echo "menu_left_rootid: $this->menu_left_rootid<br>";

		
		//$list_menuleft_id = $this->GetListParentID($this->menu_left_rootid);
		//$list_menuleft_id = $this->GetListParentID($root_id);
		$list_menuleft_id = $this->GetListParentID_top($root_id);
		
		//echo "root_id: $root_id<br>";
		//echo "list_menuleft_id: $list_menuleft_id<br>";
		$sql_all = "SELECT * FROM contents WHERE contents_parent in ".$list_menuleft_id." and langid='$langid' order by contents_order";
		//echo "sql_all: $sql_all<br>";

		
		//Kiem tra xem co bao nhieu top_parent (co submenu)
		$stmt_parent= new db_query($this->dbcon,$sql_all);
		$top_parent_no = 0;
		while ($stmt_parent->getrow())
		{
			$top_parent_id = $stmt_parent->row["contents_id"];
			$sql_parent_num = "SELECT count(*) as tong FROM contents where contents_parent='$top_parent_id'";
			//echo "sql_parent_num:$sql_parent_num<br>";
			$top_parent_num = get_values($sql_parent_num);
			if ($top_parent_num > 0) {
				$top_parent_no++;
			}
		}
		
		
		$stmt_all= new db_query($this->dbcon,$sql_all);
		$stt=0;
		while ($stmt_all->getrow())
		{
		
			
			//Bat dau vong lap, se lay cac top_parent ===========================================
			$top_parent = $stmt_all->row["contents_id"];
			//echo "top_parent:$top_parent<br>";
			
			$sql_parent_num = "SELECT count(*) as tong FROM contents where contents_parent='$top_parent'";
			//echo "sql_parent_num:$sql_parent_num<br>";
			$top_parent_num = get_values($sql_parent_num);
			if ($top_parent_num > 0) {
				$stt++;//tang bien dem
				//echo "stt: $stt - top_parent_no: $top_parent_no <br>";
			}
			
			$sql_list="SELECT * FROM contents WHERE contents_parent='$top_parent' and langid='$langid' order by contents_order ";
			//echo "sql_list: $sql_list<br>";
			$stmt= new db_query($this->dbcon,$sql_list);	
			while ($stmt->getrow())
			{
				//Vong lap con ===============================================
				//============================================================
				//echo "Vong lap con<br>";
				$fld_id = $stmt->row["contents_id"];
				//$menu_link = $stmt->row["cat_menu"];				
				$cat_type = $stmt->row["cat_type"];
				$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
				$file_link = get_values($sql_cat_type);	
				//echo "sql_cat_type: $sql_cat_type : $file_link<br>";				

				
				if ($catid == $fld_id)
				{
					$this->title = $stmt->row["contents_name"];
					
					if($target != ""){
						//echo "target: $target<br>";
						$content=$temp_list_link_menulink_blank; //Link target = _blank
					}else{
						$content=$temp_list_link; 
					}
					
					//echo "title_inc_menu_left=$title<br>";//debug
					//echo "catid: $catid title : $this->title<br>";
				}
				else
				{
							
					//Khoi tao bien Menu
					$list_menu_begin = $temp_list_begin;
					$list_menu_begin = ereg_replace("@top_parent@",$top_parent,$list_menu_begin);
					//style
					$list_menu_end = $temp_list_style;
					$list_menu_end = ereg_replace("@top_parent@",$top_parent,$list_menu_end);
				
					//Only write menu at END
					
					if($stt==$top_parent_no){
						//Write Menu
						$list_menu_write = $temp_list_write;
						$list_menu_write = ereg_replace("@top_parent@",$top_parent,$list_menu_write);
						//echo "stt=top_parent_no=$stt : $top_parent<br>";
					}
							
					//Kiem tra xem co submenu khong	
					$submenu_no = get_values("SELECT count(*) as tong FROM contents where contents_parent='$fld_id'");
					if ($submenu_no == 0) //Khong co submenu
					{
						//echo "Khong co submenu: $fld_id<br>";//debug
		
						if($target != ""){
							//echo "target: $target<br>";
							$content=$temp_list_link_menulink_blank; //template khong co submenu - Link target = _blank
						}else{
							$content=$temp_list_link; //template khong co submenu
						}
						
						//echo "<pre>$content</pre>";
			
					}
					else
					{
						//echo "Co submenu: $fld_id<br>";						
						
						$content=$temp_submenu;	//template co submenu
						
						//echo "<pre>$content</pre>";
						
						//=========== Sub Menu ==================
						//Khoi tao bien Menu
						$list_submenu_begin = $temp_submenu_begin; 
						$list_submenu_begin = ereg_replace("@cat_parent@",$fld_id,$list_submenu_begin);
						$list_submenu_begin = ereg_replace("@cat_name@",$stmt->row["contents_name"],$list_submenu_begin);
						//style
						$list_submenu_end = $temp_submenu_style;
						$list_submenu_end = ereg_replace("@cat_parent@",$fld_id,$list_submenu_end);
						
						$list_submenu.= $list_submenu_begin;
						
						$sql_list_sub = "SELECT * FROM contents where contents_parent='$fld_id' order by contents_order";
						$stmt_sub= new db_query($this->dbcon,$sql_list_sub);
						while ($stmt_sub->getrow())
						{
							 
							$submenu = $temp_submenu_list_link;
							
							$subcatid = $stmt_sub->row["contents_id"];
							//echo "subcatid: $subcatid<br>";
							$cat_type = $stmt_sub->row["cat_type"];
							$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
							$file_link_sub = get_values($sql_cat_type);								
							
							$submenu = ereg_replace("@subcatid@", "$subcatid",$submenu);
							$submenu = ereg_replace("@cat_name@",$stmt_sub->row["contents_name"],$submenu);
							$submenu = ereg_replace("@cat_parent@",$stmt_sub->row["contents_parent"],$submenu);
							$submenu = ereg_replace("@menu_link@",$menu_link,$submenu);
							$submenu = ereg_replace("@file_link@",$file_link_sub,$submenu);
							$submenu = ereg_replace("@langid@",$this->lang_id."",$submenu);
							$list_submenu.= $submenu;
							
							//echo "&nbsp;&nbsp;&nbsp;Sub Menu - List: $subcatid<br>";				
						}			
						$list_submenu.= $list_submenu_end;
						//echo "<pre>$list_submenu</pre>";
								
					}
				}
				
				//$content=$temp_list_link;
				$content=ereg_replace("@subcatid@",$stmt->row["contents_id"],$content);
				//echo "top_parent: $top_parent<br>";
				$content=ereg_replace("@catid@", "$top_parent",$content);
				$content=ereg_replace("@cat_name@",$stmt->row["contents_name"],$content);
				$content=ereg_replace("@cat_parent@",$stmt->row["contents_id"],$content);
				$content=ereg_replace("@top_parent@",$top_parent,$content);
				
				$content=ereg_replace("@menu_link@",$menu_link,$content);
				$content=ereg_replace("@file_link@",$file_link,$content);
				$content=ereg_replace("@langid@",$this->lang_id."",$content);
				
				
				$list_menu.= $content;
						
			}
			
			$list_menu = $list_menu_begin.$list_menu.$list_menu_end.$list_menu_write;
			$list_menu_all.=$list_submenu.$list_menu;
			
			//echo "<b>list_menu $top_parent</b>:<br><pre>$list_menu</pre>";
			
			//Khoi tao
			$list_menu_begin="";
			$list_menu_end="";
			$list_menu_write="";
			$list_submenu="";
			$list_menu="";
			
		
		} //Het vong lap lay top_parent
		$list_menu_all.="//hello";
		//echo "<b>Ketqua</b>:<br><pre>$list_menu_all</pre>";	

		return $list_menu_all;
	
	}//end function WriteMenu =============================
	
	function GetListParentID_0($menu_top_id)
	{
		global $langid;
		$list = "";

		$sql = "SELECT * FROM contents WHERE contents_parent='$menu_top_id' and langid='$langid' order by contents_order";
		//echo "sql: $sql<br>";
		$rs = new db_query($this->dbcon,$sql);
		$num_row = $rs->numrows();
		//echo "num_row: $num_row<br>";
		$i = 0;
		while ($rs->getrow()){
			$id = $rs->row["contents_id"]; 
			//echo "id: $id<br>";
			if ($i < $num_row -1 ){
				$list .= "$id, ";
			}else{
				$list .= "$id";
			}
			$i++;
		}//end while
		
	
		return $list;
		
	}//end function GetListParentID_0

	function GetListParentID($menu_top_id)
	{
		global $langid;
		$list = "";
		$sql = "SELECT * FROM contents WHERE contents_parent='$menu_top_id' and langid='$langid' order by contents_order";
		//echo "sql: $sql<br>";
		$rs = new db_query($this->dbcon,$sql);
		$num_row = $rs->numrows();
		//echo "num_row: $num_row<br>";
		$i = 0;
		while ($rs->getrow()){
			$id = $rs->row["contents_id"]; 
			//echo "id: $id<br>";
			if ($i < $num_row -1 ){
				$list .= "$id, ";
			}else{
				$list .= "$id";
			}
			$i++;
		}//end while
		
		$list = "($list)";
		//echo "list: $list<br>";
		
		return $list;
		
	}//end function GetListParentID

	function GetListParentID_top($menu_top_id)
	{
		global $langid;
		$list = "";
		$sql = "SELECT * FROM contents WHERE contents_parent='$menu_top_id' and langid='$langid' order by contents_order";
		//echo "sql: $sql<br>";
		$rs = new db_query($this->dbcon,$sql);
		$num_row = $rs->numrows();
		//echo "num_row: $num_row<br>";
		$i = 0;
		while ($rs->getrow()){
			$id = $rs->row["contents_id"]; 
			$list_parent = $this->GetListParentID_0($id);
			//echo "$i $num_row - $id : $list_parent<br>";
			if ( ($i < $num_row - 1)  && ($list_parent != "") ){
				$list .= $list_parent.", ";
				//echo " === $i $num_row - $id - $list_parent<br>";
			}else{
				$list .= $list_parent;
			}
			$i++;
		}//end while
		
		$list = "($list)";
		$list = eregi_replace(", )", ")", $list);
		//echo "list: $list<br>";
		
		return $list;
		
	}//end function GetListParentID
	
	//menu bar text
	function MenuBar_Text ($menu_root_id, $css_link="menubar_text", $css_nolink = "menubar_text_nolink", $line_pic="")
	{
		global $catid, $subcatid, $langid;
		if ($subcatid > 0){
			$id = $subcatid;
		}else{
			$id = $catid;
		}
		
		if($line_pic != ""){
			$tmp_line_pic = "<img src='../images_layout/menutop_line.gif' />";
		}else{
			$tmp_line_pic = "|";
		}
		
		//$this->title = "";
		$list = "";
		$list_menu = "";
		$list_begin = "<table  border='0' cellspacing='0' cellpadding='0'><tr>";
		//$css_link = "menubar_text";
		//$css_nolink = "menubar_text_nolink";
			
		$list_content_nolink = "<td align=center class='$css_nolink'>@cat_name@</td>";
			 
		$list_content_link = "<td align=center><A href='@file_link@?catid=@catid@&subcatid=@subcatid@&langid=@langid@' class='$css_link'>@cat_name@</A></td>";
		$list_content_link_tmp = '<td align=center><a href="default.htm" class="menubar_text" onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, menu1, \'150px\')" onMouseout="delayhidemenu()">@cat_name@</a></td>';
		$list_content_menulink = "<td align=center><A href='@menu_link@'  class='$css_link'>@cat_name@</A></td>";
		
		/*
		$list_line = "
					<td width='5'>
					</td><td class='menubar_text_line'>|</td>
					<td width='5'></td>";
		*/
		$list_line = "
					<td width='10'></td>
					<td class='menubar_text_line'>$tmp_line_pic</td>
					<td width='10'></td>";
							
		
		$list_end = "</tr></table>";
			  
			  
		$sql_list="SELECT * FROM contents WHERE langid='$langid' and contents_parent='$menu_root_id' order by contents_order";
	//	echo "$sql_list<br>";
		$rs= new db_query($this->dbcon,$sql_list);
		$i=0;
		while ($rs->getrow())
		{
			$fld_id = $rs->row["contents_id"];
			//echo "fld_id: $fld_id<br>";
			$menu_link = $rs->row["contents_url"];
			$cat_type = $rs->row["cat_type"];
			$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
			$file_link = get_values($sql_cat_type);	
			//echo "$fld_id - $file_link - $sql_cat_type <br>";		
			
			if ($id == $fld_id)
			{
				if ($i > 0 ){
					$content=$list_line.$list_content_nolink;	}
				else {
					$content=$list_content_nolink;}				
			}
			else
			{
				if ($i > 0 ){
						if ($menu_link != "" || $menu_link != NULL){
							$content=$list_line.$list_content_menulink;
						}else{
							$content=$list_line.$list_content_link;	
						}
					}
				else {
						if ($menu_link != "" || $menu_link != NULL){
							$content=$list_content_menulink;
						}else{
							$content=$list_content_link;	}
					}		
			}
			
			$i++;
		
			$content=ereg_replace("@catid@",$rs->row["contents_id"],$content);
			$content=ereg_replace("@subcatid@","0",$content);
			$content=ereg_replace("@cat_name@",$rs->row["contents_name"],$content);		
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			$content=ereg_replace("@file_link@",$file_link,$content);
			
			$content=ereg_replace("@langid@","$langid",$content);		
			
			$list.= $content;
		}
		$list_menu = $list_begin.$list.$list_end;
		return $list_menu;
	
	}//end function MenuBar_Text	
	function MenuBar_Text_imgbg ($menu_root_id)
	{
		global $catid, $subcatid, $langid;
		if ($subcatid > 0){
			$id = $subcatid;
		}else{
			$id = $catid;
		}
		//$this->title = "";
		$list = "";
		$list_menu = "";
		$list_begin = "<table align='center'  border='0' cellspacing='0' cellpadding='0' ><tr>";
		$css_link = "menubar_text";
		$css_nolink = "menubar_text_nolink";

		/*
		$list_line = "
					<td width='5'>
					</td><td class='menubar_text_line'>|</td>
					<td width='5'></td>";
		*/
		//*		
		$list_line = "
					<td class='menubar_text_line'><img src='../images_layout/menubar_line.gif' width='8' height='24' /></td>
		";
				
		//*/
		$tmp_list_line = "";
		


			
		$tmp_link = '		
		<table  height="24" border="0" cellpadding="0" cellspacing="0">
		  <tr>
			<td width="5" background="../images_layout/menubar_left_0.gif">&nbsp;</td>
			<td  nowrap="nowrap" background="../images_layout/menubar_center_0.gif" @class@ align="center">@name@</td>
			<td width="5" background="../images_layout/menubar_right_0.gif"></td>
		  </tr>
		</table>		
		';
		
		$tmp_nolink = '
		<table  height="24" border="0" cellpadding="0" cellspacing="0">
		  <tr>
			<td width="5" background="../images_layout/menubar_left_1.gif">&nbsp;</td>
			<td  nowrap="nowrap" background="../images_layout/menubar_center_1.gif" @class@ align="center">@name@</td>
			<td width="5" background="../images_layout/menubar_right_1.gif"></td>
		  </tr>
		</table>		
		';
		
		//$list_content_nolink = "<td align=center class='$css_nolink'>@cat_name@</td>";
		$list_content_nolink = "<td>".$tmp_nolink."</td>";
		$list_content_nolink = ereg_replace("@class@", "class='$css_nolink'", $list_content_nolink);
		$list_content_nolink = ereg_replace("@name@", "@cat_name@", $list_content_nolink);
		
		//$list_content_link = "<td align=center><A href='@file_link@?catid=@catid@&subcatid=@subcatid@&langid=@langid@' class='$css_link'>@cat_name@</A></td>";
		$list_content_link = "<td>".$tmp_link."</td>";
		$list_content_link = ereg_replace("@class@", "", $list_content_link);
		$list_content_link = ereg_replace("@name@", "<A href='@file_link@?catid=@catid@&subcatid=@subcatid@&loaitinid=@loaitinid@&langid=@langid@' class='$css_link'>@cat_name@</A>", $list_content_link);		
			 
		
		
		//$list_content_menulink = "<td align=center><A href='@menu_link@'  class='$css_link'>@cat_name@</A></td>";
		$list_content_menulink = "<td>".$tmp_link."</td>";
		$list_content_menulink = ereg_replace("@class@", "", $list_content_menulink);
		$list_content_menulink = ereg_replace("@name@", "<A href='@menu_link@'  class='$css_link'>@cat_name@</A>", $list_content_menulink);		
				
		$list_content_link_tmp = '<td align=center><a href="default.htm" class="menubar_text" onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, menu1, \'150px\')" onMouseout="delayhidemenu()">@cat_name@</a></td>';

		
		$list_end = "</tr></table>";
			  
			  
		$sql_list="SELECT * FROM contents WHERE langid='$langid' and contents_parent='$menu_root_id' order by contents_order";
	//	echo "$sql_list<br>";
		$rs= new db_query($this->dbcon,$sql_list);
		$i=0;$j=0;
		
		$total = $rs->numrows();
		//echo "total:$total<br>";
		while ($rs->getrow())
		{
		
			$tmp_list_line = $list_line;
			
			$fld_id = $rs->row["contents_id"];
			$loaitinid = $rs->row["loaitin_id"];
			//echo "fld_id: $fld_id<br>";
			$menu_link = $rs->row["contents_url"];
			$cat_type = $rs->row["cat_type"];
			$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
			$file_link = get_values($sql_cat_type);	
			//echo "$fld_id - $file_link - $sql_cat_type <br>";		
			//echo "i:$i - j: $j<br>";
			if ($id == $fld_id)
			{

				if ($i > 0 ){
					$tmp_list_line = "";
					$content=$tmp_list_line.$list_content_nolink;	}
				else {
					$content=$list_content_nolink;}				
				
				$j++;
			}
			else
			{
				if ($i > 0 ){
					if($j > 0){
						$tmp_list_line = "";
						$j=0;
					}
					if ($menu_link != "" || $menu_link != NULL){
						$content=$tmp_list_line.$list_content_menulink;
					}else{
						$content=$tmp_list_line.$list_content_link;	
					}
				}else {
					if ($menu_link != "" || $menu_link != NULL){
						$content=$list_content_menulink;
					}else{
						$content=$list_content_link;	
					}
				}		
			}
			
			$i++;
		
			$content=ereg_replace("@catid@",$rs->row["contents_id"],$content);
			$content=ereg_replace("@loaitinid@","$loaitinid",$content);
			$content=ereg_replace("@subcatid@","0",$content);
			$content=ereg_replace("@cat_name@",$rs->row["contents_name"],$content);		
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			$content=ereg_replace("@file_link@",$file_link,$content);
			
			$content=ereg_replace("@langid@","$langid",$content);		
			
			$list.= $content;
		}
		$list_menu = $list_begin.$list.$list_end;
		return $list_menu;
	
	}//end function MenuBar_Text	
	
	function MenuBar_Text_Bullet ($menu_root_id)
	{
		global $catid, $subcatid, $langid;
		if ($subcatid > 0){
			$id = $subcatid;
		}else{
			$id = $catid;
		}
		//$this->title = "";
		$list = "";
		$list_menu = "";
		$list_begin = "<table align='center' border='0'><tr>";
		$css_link = "menubar_text";
		$css_nolink = "menubar_text_nolink";
			
		$list_content_nolink = "<td class='$css_nolink'>@cat_name@</td>";
			 
		$list_content_link = "<td><A href='@file_link@?catid=@catid@&subcatid=@subcatid@&langid=@langid@' class='$css_link'>@cat_name@</A></td>";
		$list_content_link_tmp = '<td><a href="default.htm" class="menubar_text" onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, menu1, \'150px\')" onMouseout="delayhidemenu()">@cat_name@</a></td>';
		$list_content_menulink = "<td><A href='@menu_link@'  class='$css_link'>@cat_name@</A></td>";
		
		$list_line = "
					<td width='1'>
					</td><td><img src='../images_layout/menubar_bullet.gif'></td>
					<td width='1'></td>";
		
		$list_end = "</tr></table>";
			  
			  
		$sql_list="SELECT * FROM contents WHERE langid='$langid' and contents_parent='$menu_root_id' order by contents_order";
	//	echo "$sql_list<br>";
		$rs= new db_query($this->dbcon,$sql_list);
		$i=0;
		while ($rs->getrow())
		{
			$fld_id = $rs->row["contents_id"];
			//echo "fld_id: $fld_id<br>";
			$menu_link = $rs->row["contents_url"];
			$cat_type = $rs->row["cat_type"];
			$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
			$file_link = get_values($sql_cat_type);	
			//echo "$fld_id - $file_link - $sql_cat_type <br>";		
			
			if ($id == $fld_id)
			{
				if ($i > 0 ){
					$content=$list_line.$list_content_nolink;	}
				else {
					$content=$list_content_nolink;}				
			}
			else
			{
				if ($i > 0 ){
						if ($menu_link != "" || $menu_link != NULL){
							$content=$list_line.$list_content_menulink;
						}else{
							$content=$list_line.$list_content_link;	
						}
					}
				else {
						if ($menu_link != "" || $menu_link != NULL){
							$content=$list_content_menulink;
						}else{
							$content=$list_content_link;	}
					}		
			}
			
			$i++;
		
			$content=ereg_replace("@catid@",$rs->row["contents_id"],$content);
			$content=ereg_replace("@subcatid@","0",$content);
			$content=ereg_replace("@cat_name@",$rs->row["contents_name"],$content);		
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			$content=ereg_replace("@file_link@",$file_link,$content);
			
			$content=ereg_replace("@langid@","$langid",$content);		
			
			$list.= $content;
		}
		$list_menu = $list_begin.$list.$list_end;
		return $list_menu;
	
	}//end function MenuBar_Text_Bullet	

	function MenuBar_Text_ncap ($menu_root_id)
	{
		global $catid, $subcatid, $langid;
		//$this->title = "";
		$list = "";
		$list_menu = "";
		$list_begin = "<table align='left' border='0' ><tr>";
		$css_link = "menubar_text";
		$css_nolink = "menubar_text_nolink";
			
		$list_content_nolink = "<td align='center' class='$css_nolink'>@cat_name@</td>";
			 
		$list_content_link = "<td align='center'><A href='@file_link@?catid=@catid@&subcatid=@subcatid@&langid=@langid@' class='$css_link'>@cat_name@</A></td>";
		$list_content_link_tmp = '<td align="center"><a href="#" class="menubar_text" onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, menu@catid@, \'150px\')" onMouseout="delayhidemenu()">@cat_name@</a></td>';
		$list_content_sublink = '<td  align="center"><a href="#" class="menubar_text_sublink" onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, menu@catid@, \'150px\')" onMouseout="delayhidemenu()">@cat_name@</a></td>';
		$list_content_menulink = "<td align='center'><A href='@menu_link@'  class='$css_link'>@cat_name@</A></td>";
		
		$list_line = "
					<td width='5'>
					</td><td width='1'><img src='../images_layout/menubar_line.jpg'></td>
					<td width='5'></td>";
		
		$list_end = "</tr></table>";
			  
			  
		$sql_list="SELECT * FROM cat WHERE enable=1 and cat_parent='$menu_root_id' order by cat_order";
		//echo "$sql_list<br>";
		$rs= new db_query($this->dbcon,$sql_list);
		$i=0;
		while ($rs->getrow())
		{
			$fld_id = $rs->row["catid"];
			$cat_type = $rs->row["cat_type"];
			$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
			$file_link = get_values($sql_cat_type);	
			//echo "$fld_id - $file_link - $sql_cat_type <br>";
			$submenu_no = get_values("SELECT count(*) as tong FROM cat where cat_parent='$fld_id'");
			//echo "submenu_no: $submenu_no<br>";			
			$menu_link = $rs->row["cat_menu"];
			if ($catid == $fld_id )
			{
				if($subcatid == 0){
					$list_tmp = $list_content_nolink;
				}else{
					$list_tmp = $list_content_sublink;
				}
				
				if ($i > 0 ){
					$content=$list_line.$list_tmp;	}
				else {
					$content=$list_tmp;}				
			}
			else
			{
				if ($i > 0 ){
						if ($menu_link != "" || $menu_link != NULL){
							$content=$list_line.$list_content_menulink;
						}else{
							$content=$list_line.$list_content_link;	
							//echo "fld_id: $fld_id<br>";
							if ($submenu_no > 0){
								$content=$list_line.$list_content_link_tmp;
							}
						}
					}
				else {
						if ($menu_link != "" || $menu_link != NULL){
							$content=$list_content_menulink;
						}else{
							$content=$list_content_link;	}
					}		
			}
			
			$i++;
			$subcat_id = $this->Get_Subcatid($fld_id);
		
			$content=ereg_replace("@catid@",$rs->row["catid"],$content);
			$content=ereg_replace("@subcatid@","$subcat_id",$content);
			$content=ereg_replace("@cat_name@",$rs->row["cat_name"],$content);
			$content=ereg_replace("@cat_menu@",$rs->row["cat_menu"],$content);	
		
			$content=ereg_replace("@menuid@",$rs->row["catid"],$content);		
			$content=ereg_replace("@menu_link@",$menu_link,$content);	
			$content=ereg_replace("@file_link@",$file_link,$content);	
			$content=ereg_replace("@langid@","$langid",$content);		
			
			$list.= $content;
		}
		$list_menu = $list_begin.$list_line.$list.$list_line.$list_end;
		return $list_menu;
	
	}//end function MenuBar_Text_ncap
	
	function MenuBar_Column ($menu_root_id)
	{
		global $catid, $langid;
		$title = "";
		$list = "";
		$list_menu = "";
		$list_begin = "<table align='center' border='0' width='95%' height='100%' cellspacing='0' cellpadding='0'><tr>";
		$css_link = "menubar_text";
		$css_nolink = "menubar_text_nolink";
			
		$list_content_nolink = "<td align='center' class='menu_bar_over'>@cat_name@</td>";
			 
		$list_content_link = '
			<td OnClick="menubar_link(\'@file_link@?catid=@catid@&subcatid=@subcatid@&loaitinid=@loaitinid@&langid=@langid@\')" id="menubar_@catid@" class="menu_bar_normal" onMouseOver="menubar_over(\'@catid@\')" onMouseOut="menubar_normal(\'@catid@\')">
			@cat_name@			
			</td>';
		$list_content_menulink = '
			<td OnClick="menubar_link(\'@menu_link@\')" id="menubar_@catid@" class="menu_bar_normal" onMouseOver="menubar_over(\'@catid@\')" onMouseOut="menubar_normal(\'@catid@\')">
			@cat_name@
			</td>';	
		$list_content_link_submenu = '
			<td id="menubar_@catid@" class="menu_bar_normal" onMouseOver="menubar_over(\'@catid@\');dropdownmenu(this, event, menu@catid@, \'150px\');" onMouseOut="menubar_normal(\'@catid@\');delayhidemenu()">
			@cat_name@
			</td>';	
			
		$list_content_link_submenu_select = '
			<td id="menubar_@catid@" class="menu_bar_over" onMouseOver="menubar_over(\'@catid@\');dropdownmenu(this, event, menu@catid@, \'150px\');" onMouseOut="menubar_normal(\'@catid@\');delayhidemenu()">
			@cat_name@
			</td>';				
					
		//*

		$list_line = "
					<td ><img src='../images_layout/menubar_line.gif' width='2' height='24' /></td>
		";		
		//$list_line = "";
		
		$list_end = "</tr></table>";
			  
			  
		$sql_list="SELECT * FROM contents WHERE contents_parent='$menu_root_id' order by contents_order";
		//echo "$sql_list<br>";
		$rs= new db_query($this->dbcon,$sql_list);
		$i=0;
		while ($rs->getrow())
		{
			$fld_id = $rs->row["contents_id"];
			$loaitinid = $rs->row["loaitin_id"];
			$menu_link = $rs->row["contents_url"];
			//echo "catid:$fld_id  -  cat_menu: $menu_link <br>";//debug	
			
			$cat_type = $rs->row["cat_type"];
			$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
			$file_link = get_values($sql_cat_type);	
			
			$submenu_no = get_values("SELECT count(*) as tong FROM contents where contents_parent='$fld_id'");
			//echo "submenu_no: $submenu_no<br>";				
			
			if($file_link == "_blank"){
				$target = "target = _blank";
			}else{
				$target = "";
			}
			
			if($i > 0){
				$line = $list_line;
			}else{
				$line = "";
			}
			if ($catid == $fld_id){
				if($submenu_no > 0){
					$content=$line.$list_content_link_submenu_select;
				}else{
					$content=$line.$list_content_nolink;
				}
				$this->title = $rs->row["contents_name"];
				//echo ("title:".$this->title."<br>");
			}else{
				if ($menu_link != "" || $menu_link != NULL){
					$content=$line.$list_content_menulink;
				}else{
					if ($submenu_no > 0){
						$content=$line.$list_content_link_submenu;
					}else{
						$content=$line.$list_content_link;
					}





				}
			}
			
			$i++;
			$subcatid = $this->Get_Subcatid($fld_id);
		
			$content=ereg_replace("@catid@",$fld_id, $content);
			$content=ereg_replace("@subcatid@","$subcatid", $content);
			$content=ereg_replace("@cat_name@",$rs->row["contents_name"], $content);
			$content=ereg_replace("@cat_menu@",$menu_link, $content);	
		
			$content=ereg_replace("@menuid@",$fld_id,$content);		
			$content=ereg_replace("@menu_link@",$menu_link,$content);	
			$content=ereg_replace("@langid@","$langid",$content);		
			$content=ereg_replace("@file_link@","$file_link",$content);	
			$content=ereg_replace("@loaitinid@","$loaitinid",$content);
			$content=ereg_replace("@target@","$target",$content);		
			
			$list.= $content;
		}
		$list_menu = $list_begin.$list_line.$list.$list_line.$list_end;
		return $list_menu;
	
	}//end function MenuBar_Column	


	function MenuBar_Hover ($menu_root_id)
	{
		global $catid, $langid, $arr_tintuc_id;
		$title = "";
		$list = "";
		$list_menu = "";
		$list_begin = "<table align='center' border='0' width='100%' height='100%' cellspacing='0' cellpadding='0'><tr>";
			
		$list_content_nolink = "<td><img src='@image_path_over@' name='@image_name@'  border='0'></td>";			 
		$list_content_link = "<td><a href='@file_link@?catid=@catid@&subcatid=@subcatid@&loaitinid=@loaitinid@&langid=@langid@' onMouseOut=\"Nut_swapImgRestore()\" onMouseOver=\"Nut_swapImage('@image_name@','','@image_path_over@',1)\"><img src='@image_path@' name='@image_name@' border='0'></a></td>";	
		$list_content_menulink = "<td><a href='@menu_link@' onMouseOut=\"Nut_swapImgRestore()\" onMouseOver=\"Nut_swapImage('@image_name@','','@image_path_over@',1)\"><img src='@image_path@' name='@image_name@' border='0'></a></td>";	
		$list_content_sublink = '<td  align="center"><a href="#" onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, menu@catid@, \'160px\'); Nut_swapImage(\'@image_name@\',\'\',\'@image_path_over@\',1) " onMouseout="delayhidemenu();Nut_swapImgRestore()"><img src="@image_path@" name="@image_name@" border="0"></a></td>';
		$list_content_sublink_select = '<td  align="center"><a href="#" onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, menu@catid@, \'160px\'); Nut_swapImage(\'@image_name@\',\'\',\'@image_path@\',1) " onMouseout="delayhidemenu();Nut_swapImgRestore()"><img src="@image_path_over@" name="@image_name@" border="0"></a></td>';
		$list_line = "<td width='10'></td>";		
	
		$list_end = "</tr></table>";
		$path = "../uploads/noidung/";	
			  
		$sql_list="SELECT * FROM contents WHERE contents_parent='$menu_root_id' order by contents_order";
		//echo "$sql_list<br>";
		$rs= new db_query($this->dbcon,$sql_list);
		$i=0;
		while ($rs->getrow())
		{
			$fld_id = $rs->row["contents_id"];
			$pic1 = $rs->row["pic1"];
			$pic2 = $rs->row["pic2"];
			$image_name = "pic_".$fld_id;
			$image_path = $path.$pic1;
			$image_path_over = $path.$pic2;
			$loaitinid = $rs->row["loaitin_id"];
			$menu_link = $rs->row["contents_url"];
			//echo "catid:$fld_id  -  cat_menu: $menu_link <br>";//debug	
			
			$cat_type = $rs->row["cat_type"];
			$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
			$file_link = get_values($sql_cat_type);	
					
			if($file_link == "_blank"){
				$target = "target = _blank";
			}else{
				$target = "";
			}
			
			if($i > 0){
				$line = $list_line;
			}else{
				$line = "";
			}
			if ($catid == $fld_id){
				if($fld_id == $arr_tintuc_id[$langid]["dir"]){
					$content=$line.$list_content_sublink_select;
				}else{
					$content=$line.$list_content_nolink;
					$this->title = $rs->row["contents_name"];
					//echo ("title:".$this->title."<br>");
				}
			}else{
				if ($menu_link != "" || $menu_link != NULL){
					$content=$line.$list_content_menulink;
				}elseif($fld_id == $arr_tintuc_id[$langid]["dir"]){
					$content=$line.$list_content_sublink;
				}else{
					$content=$line.$list_content_link;
				}
			}
			
			$i++;
			if($fld_id != $arr_tintuc_id[$langid]["news"]){
				$subcatid = $this->Get_Subcatid($fld_id);
			}else{
				$subcatid  = 0;
			}
		
			$content=ereg_replace("@catid@",$fld_id, $content);
			$content=ereg_replace("@subcatid@","$subcatid", $content);

			$content=ereg_replace("@image_name@",$image_name, $content);	
			$content=ereg_replace("@image_path@",$image_path, $content);	
			$content=ereg_replace("@image_path_over@",$image_path_over, $content);	
		
			$content=ereg_replace("@menuid@",$fld_id,$content);		
			$content=ereg_replace("@menu_link@",$menu_link,$content);	
			$content=ereg_replace("@langid@","$langid",$content);		
			$content=ereg_replace("@file_link@","$file_link",$content);	
			$content=ereg_replace("@loaitinid@","$loaitinid",$content);
			$content=ereg_replace("@target@","$target",$content);		
			
			$list.= $content;
		}
		$list_menu = $list_begin.$list_line.$list.$list_line.$list_end;
		return $list_menu;
	
	}//end function MenuBar_Column	

	
	function MenuBar_Image_Background ($menu_root_id)
	{
		global $catid, $langid;
		$title = "";
		$list = "";
		$list_menu = "";
		$list_begin = "<table align='center' border='0' cellspacing='0' cellpadding='0' height='24'><tr>";
		$css_link = "menu_bar";
		$css_nolink = "menu_bar_nolink";
		$td_width = "89";
			
		$list_content_nolink = "<td width='$td_width' align='center' class='$css_nolink'>@cat_name@</td>";
			 
		$list_content_link = "
			<td width='$td_width' align='center' class=menu onclick=mClk(this); onmouseover=mOvr(this); onmouseout=mOut(this);>
			<A href='index.php?catid=@catid@&subcatid=@subcatid@&langid=@langid@' class='$css_link'>
			@cat_name@
			</A></td>";
		$list_content_menulink = "
			<td  width='$td_width' align='center' class=menu onclick=mClk(this); onmouseover=mOvr(this); onmouseout=mOut(this);>
			<A href='@menu_link@'  class='$css_link'>@cat_name@</A></td>";
		
		$list_line = "
					<td width='10'></td>
					";
		
		$list_end = "</tr></table>";
			  
			  
		$sql_list="SELECT * FROM cat WHERE enable=1 and cat_parent='$menu_root_id' order by cat_order";
		//echo "$sql_list<br>";
		$rs= new db_query($this->dbcon,$sql_list);
		$i=0;
		while ($rs->getrow())
		{
			$fld_id = $rs->row["catid"];
			$menu_link = $rs->row["cat_menu"];
			//echo "catid:$fld_id  -  cat_menu: $menu_link <br>";//debug	
			if ($catid == $fld_id)
			{
				if ($i > 0 ){
					$content=$list_line.$list_content_nolink;	}
				else {
					$content=$list_content_nolink;}
				
				$this->title = $rs->row["cat_name"];
				//echo ("title:".$this->title."<br>");
			}
			else
			{
				if ($i > 0 ){
						if ($menu_link != "" || $menu_link != NULL){
							$content=$list_line.$list_content_menulink;
						}else{
							$content=$list_line.$list_content_link;	}
					}
				else {
						if ($menu_link != "" || $menu_link != NULL){
							$content=$list_content_menulink;
						}else{
							$content=$list_content_link;	}
					}		
			}
			
			$i++;
			$subcatid = $this->Get_Subcatid($fld_id);
		
			$content=ereg_replace("@catid@",$rs->row["catid"],$content);
			$content=ereg_replace("@subcatid@","$subcatid",$content);
			$content=ereg_replace("@cat_name@",$rs->row["cat_name"],$content);
			$content=ereg_replace("@cat_menu@",$rs->row["cat_menu"],$content);	
		
			$content=ereg_replace("@menuid@",$rs->row["catid"],$content);		
			$content=ereg_replace("@menu_link@",$menu_link,$content);	
			$content=ereg_replace("@langid@","$langid",$content);		
			
			$list.= $content;
		}
		$list_menu = $list_begin.$list_line.$list.$list_line.$list_end;
		return $list_menu;
	
	}//end function MenuBar_Column		
	
	function SubMenuBar_Text($parent_id, $file_link="", $css_link="")
	{
		global $subcatid;
		$this->title = "";
		if ($file_link == ""){
			$file_link = "index.php";
		}
		if($css_link == ""){
			$css_link = "menu_left";
		}
		$css_nolink = $css_link."_nolink";
		
		
		$td_width = "12";
		$title = "";
		$img_bullet = "../images/bullet/ovuong.gif";
		//$td_bullet = "<td width='$td_width' align='center' valign='top' class='menuleft_sub'><font color=#ffffff>-</font></td>";
		$td_bullet = "";
		$td_line = "<TD height=1 bgcolor=#BEBEBF colspan='2' onMouseOver=\"window.hideActiveMenus();\"></TD>";
		$tr_line = "<TR>$td_line</TR>";
		
		
		//===========================================================================
		//Left Menu 
		$list_left = '<TABLE width="90%" border=0 cellpadding="0" cellspacing="0"  align="center" > ';
			
		$list_content_nolink = "
			
			<TR>
			$td_bullet
			<TD height=20 align='left' class='$css_nolink'>@cat_name@</TD>
			</TR>
		";
		$list_content_link_nosubmenu = "			
			<TR>
			 $td_bullet				
			 <TD width='92%' height=20 align='left' class='menuleft_sub'>
			 <A  href='$file_link?catid=@catid@&subcatid=@subcatid@&langid=@langid@' class='$css_link'>@cat_name@</A>
			</TD>
			</TR>
		";		
		$list_content_link = "			
			<TR>
			 $td_bullet				
			 <TD width='92%' height=20 align='left' class='menuleft_sub'>
			 <a class=\"$css_link\" href=\"javascript://\" onMouseOver=\"window.showMenu(window.myMenu@subcatid@);\">@cat_name@</a>
			</TD>
			</TR>
		";
		
		$list_content_menulink = "
			
			<TR> 
			$td_bullet								
			 <TD height=20 align='left' class='menuleft_sub'>
			 <A  href='@menu_link@' @target@ class='$css_link'>@cat_name@</A>
			</TD>
			</TR>
		";
		
		
		$sql_list="SELECT * FROM cat WHERE enable=1 and cat_parent='$parent_id' order by cat_order";
		//echo "sql_list: $sql_list<br>";
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{
			if ($i > 0 && $i < $num_row){
				$line = $tr_line;
			}else{
				$line = "";
			}
			$fld_id = $stmt->row["catid"];
			//echo "fld_id: $fld_id<br>";
			$menu_link = $stmt->row["cat_menu"];
			$target = $stmt->row["cat_pic1"];
			//echo "target: $target<br>";
			if($target == "_blank") {
				$target="target='_blank'";
			}else{
				$target="";
			}			

			if ($subcatid == $fld_id)
			{
				$content=$line.$list_content_nolink;
				$this->title = $stmt->row["cat_name"];
				//echo "catid: $fld_id title: $this->title<br>";
			}
			else
			{		
				$submenu_no = get_values("SELECT count(*) as tong FROM cat where cat_parent='$fld_id'");
		
				if ($submenu_no == 0) //Khong co submenu
				{		
					if ($menu_link != "" || $menu_link != NULL){
						$content=$line.$list_content_menulink;
					}
					else{
						$content=$line.$list_content_link_nosubmenu; //template khong co submenu	
					}
				}
				else 
				{
					$content=$line.$list_content_link;
					//echo "co submenu<br>";
					//echo "<pre>$content</pre>";	
				}						
			
			}
		
			$content=ereg_replace("@catid@","$parent_id",$content);
			$content=ereg_replace("@subcatid@",$stmt->row["catid"],$content);
			$content=ereg_replace("@cat_name@",$stmt->row["cat_name"],$content);
		
			$content=ereg_replace("@menuid@",$stmt->row["catid"],$content);
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			$content=ereg_replace("@target@",$target,$content);
			
			$content=ereg_replace("@langid@",$this->lang_id,$content);
			
			//print "result:<br><pre>".htmlspecialchars($content, ENT_QUOTES)."</pre>"; //debug
			
			$list_left.= $content;
			$i++;
		}
		
		$list_left.= "   
		</TABLE>";
		
		
		$list_menu = $list_left;
		
		return $list_menu;		
	}	//end function SubMenuBar_Text

	function SubMenuBar_TextBullet($parent_id, $file_default_link="", $css_link="")
	{
		global $subcatid;
		$file_link = "";
		$this->title = "";
		if ($file_default_link == ""){
			$file_default_link = "index.php";
		}
		$file_sanpham_link = "content.php";
		if($css_link == ""){
			$css_link = "menu_left";
		}
		$css_nolink = $css_link."_nolink";
		
		$td_height = "25";
		$td_width = "20";
		$title = "";
		$img_bullet = "<img src='../images/left_bullet.jpg'>";
		$td_bullet = "<td width='$td_width' align='center' valign='baseline' class='menuleft_sub'>$img_bullet</td>";
		//$td_bullet = "";
		$td_line = "<TD height=1 bgcolor=#89CFFE colspan='2' onMouseOver=\"window.hideActiveMenus();\"></TD>";
		$tr_line = "<TR>$td_line</TR>";
		
		
		//===========================================================================
		//Left Menu 
		$list_left = '<TABLE width="98%" border=0 cellpadding="2" cellspacing="0"  align="left" > ';
			
		$list_content_nolink = "
			
			<TR>
			$td_bullet
			<TD height='$td_height' align='left' class='$css_nolink'>@cat_name@</TD>
			</TR>
		";
		$list_content_link_nosubmenu = "			
			<TR>
			 $td_bullet				
			 <TD width='92%' height='$td_height' align='left' class='menuleft_sub'>
			 <A  href='@file_link@?catid=@catid@&subcatid=@subcatid@&langid=@langid@' class='$css_link'>@cat_name@</A>
			</TD>
			</TR>
		";		
		$list_content_link = "			
			<TR>
			 $td_bullet				
			 <TD width='92%' height='$td_height' align='left' class='menuleft_sub'>
			 <a class=\"$css_link\" href=\"javascript://\" onMouseOver=\"window.showMenu(window.myMenu@subcatid@);\">@cat_name@</a>
			</TD>
			</TR>
		";
		
		$list_content_menulink = "
			
			<TR> 
			$td_bullet								
			 <TD height='$td_height' align='left' class='menuleft_sub'>
			 <A  href='@menu_link@' @target@ class='$css_link'>@cat_name@</A>
			</TD>
			</TR>
		";
		
		
		$sql_list="SELECT * FROM cat WHERE enable=1 and cat_parent='$parent_id' order by cat_order";
		//echo "sql_list: $sql_list<br>";
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{
			if ($i > 0 && $i < $num_row){
				$line = $tr_line;
			}else{
				$line = "";
			}
			$fld_id = $stmt->row["catid"];
			//echo "fld_id: $fld_id<br>";
			$menu_link = $stmt->row["cat_menu"];
			$target = $stmt->row["cat_pic1"];
			//echo "target: $target<br>";
			if($target == "_blank") {
				$target="target='_blank'";
			}else{
				$target="";
			}
			$cat_type = $stmt->row["cat_type"];
			switch ($cat_type){
				case 0:
					//echo "cattype=0<br>";
					$file_link = $file_default_link;
					break;
				case 1:
					//echo "cattype=1<br>";
					$file_link = $file_sanpham_link;
					break;
			}

			if ($subcatid == $fld_id)
			{
				$content=$line.$list_content_nolink;
				$this->title = $stmt->row["cat_name"];
				//echo "catid: $fld_id title: $this->title<br>";
			}
			else
			{		
				$submenu_no = get_values("SELECT count(*) as tong FROM cat where cat_parent='$fld_id'");
		
				if ($submenu_no == 0) //Khong co submenu
				{		
					if ($menu_link != "" || $menu_link != NULL){
						$content=$line.$list_content_menulink;
					}
					else{
						$content=$line.$list_content_link_nosubmenu; //template khong co submenu	
					}
				}
				else 
				{
					$content=$line.$list_content_link;
					//echo "co submenu<br>";
					//echo "<pre>$content</pre>";	
				}						
			
			}
		
			$content=ereg_replace("@catid@","$parent_id",$content);
			$content=ereg_replace("@subcatid@",$stmt->row["catid"],$content);
			$content=ereg_replace("@cat_name@",$stmt->row["cat_name"],$content);
		
			$content=ereg_replace("@menuid@",$stmt->row["catid"],$content);
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			$content=ereg_replace("@target@",$target,$content);
			
			$content=ereg_replace("@langid@",$this->lang_id,$content);
			$content=ereg_replace("@file_link@", "$file_link",$content);
			
			//print "result:<br><pre>".htmlspecialchars($content, ENT_QUOTES)."</pre>"; //debug
			
			$list_left.= $content;
			$i++;
		}
		
		$list_left.= $tr_line."   
		</TABLE>";
		
		
		$list_menu = $list_left;
		
		return $list_menu;		
	}	//end function SubMenuBar_TextBullet


	function MenuLeft_Sub_TextBullet_cap1($parent_id, $file_default_link="", $css_link="")
	{
		global $subcatid, $catid, $langid;
		$file_link = "";
		$this->title = "";
		if ($file_default_link == ""){
			$file_default_link = "index.php";
		}
		$file_sanpham_link = "content.php";
		if($css_link == ""){
			$css_link = "menusub_left_1";
		}
		$css_nolink = $css_link."_nolink";
		$css_header = $css_link."_header";
		$css_select = $css_link."_select";
		
		$td_height = "23";
		$td_width = "138";
		$width = "width = '$td_width'";
		$title = "";
		$img_bullet = "<img src='../images_layout/bullet_2.gif'>";
		//$img_bullet = "+";
		$td_bullet = "<td align='center' class='$css_nolink' >$img_bullet</td>";
		//$td_bullet = "";
		//$td_line = "<TD height=1 bgcolor='#003660' colspan='2' onMouseOver=\"window.hideActiveMenus();\"></TD>";
		//$td_line_2 = "<TD height=1 bgcolor='#ffffff' colspan='2' onMouseOver=\"window.hideActiveMenus();\"></TD>";
		$td_line = "<TD height=1 colspan='2' onMouseOver=\"window.hideActiveMenus();\"><img src='../images_layout/menu_line.gif' ></TD>";
		$tr_line = "<TR>$td_line</TR>";
		
		
		//===========================================================================
		//Left Menu 
		$list_left = '';
			
		$list_content_nolink = "			
			<TR>
			$td_bullet
			<TD $width height='$td_height' align='left' class='$css_nolink'>@cat_name@</TD>
			</TR>
		";
		$list_content_link_nosubmenu = "			
			<TR>
			 $td_bullet				
			 <TD $width height='$td_height' align='left' >
			 <A  href='@file_link@?catid=@catid@&subcatid=@subcatid@&langid=@langid@' class='$css_link' onMouseOver=\"window.hideActiveMenus();\">@cat_name@</A>
			</TD>
			</TR>
		";		
		$list_content_link = "			
			<TR>
			 $td_bullet				
			 <TD $width height='$td_height' align='left' >
			 <a class=\"$css_link\" href=\"#\">@cat_name@</a>
			</TD>
			</TR>
		";
		
		//$show_icon_subcat = "cat.php?catid=@catid@&id=@subcatid@&langid=@langid@";
		$show_icon_subcat = "#";
		
		$list_content_menulink_2 = "			
			<TR>
			$td_bullet				
			 <TD $width height='$td_height' align='left' class='$css_header'>
			 <a class=\"$css_link\" href=\"$show_icon_subcat\" onMouseOver=\"window.showMenu(window.myMenu@subcatid@);\">@cat_name@ &gt;&gt;</a>
			</TD>
			</TR>
		";
		
		$list_content_menulink_2_select = "			
			<TR>
			$td_bullet				
			 <TD $width height='$td_height' align='left' class='$css_header'>
			 <a class=\"$css_select\" href=\"$show_icon_subcat\" onMouseOver=\"window.showMenu(window.myMenu@subcatid@);\">@cat_name@ &gt;&gt;</a>
			</TD>
			</TR>
		";		
		
		
		$sql_list="SELECT * FROM contents WHERE langid='$langid' and contents_parent='$parent_id' order by contents_order";
		//echo "sql_list: $sql_list<br>";
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{
			if ($i > 0 && $i < $num_row){
				$line = $tr_line;
			}else{
				$line = "";
			}
			$fld_id = $stmt->row["contents_id"];
			$cat_type = $stmt->row["cat_type"];
			$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
			$file_link = get_values($sql_cat_type);	
			//echo "$fld_id - $file_link - $sql_cat_type <br>";		

			if ($subcatid == $fld_id)
			{
				$content=$line.$list_content_nolink;
				$this->title = $stmt->row["contents_name"];
				//echo "catid: $fld_id title: $this->title<br>";
			}
			else
			{		
				$submenu_no = get_values("SELECT count(*) as tong FROM contents where contents_parent='$fld_id'");
		
				if ($submenu_no == 0) //Khong co submenu
				{		
					if ($menu_link != "" || $menu_link != NULL){
						$content=$line.$list_content_menulink;
					}
					else{
						$content=$line.$list_content_link_nosubmenu; //template khong co submenu
					}
				}
				else 
				{	//submenu cap 2
					//echo "catid: $catid - fld_id: $fld_id<br>";
					if ($catid == $fld_id){
						$content=$line.$list_content_menulink_2_select;
					}else{
						$content=$line.$list_content_menulink_2;
					}
					$content = ereg_replace("@list_menulink_2@", $this->MenuLeft_Sub_TextBullet_cap2($fld_id), $content);
					//echo "co submenu<br>";
					//echo "<pre>$content</pre>";	
				}						
			
			}
		
			$content=ereg_replace("@catid@","$parent_id",$content);
			$content=ereg_replace("@subcatid@",$stmt->row["contents_id"],$content);
			$content=ereg_replace("@cat_name@",$stmt->row["contents_name"],$content);
		
			$content=ereg_replace("@menuid@",$stmt->row["contents_id"],$content);
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			$content=ereg_replace("@target@",$target,$content);
			
			$content=ereg_replace("@langid@",$this->lang_id,$content);
			$content=ereg_replace("@file_link@", "$file_link",$content);
			
			//print "result:<br><pre>".htmlspecialchars($content, ENT_QUOTES)."</pre>"; //debug
			
			$list_left.= $content;
			$i++;
		}
		
		
		$list_menu = $list_left;
		
		return $list_menu;		
	}	//end function SubMenuBar_TextBullet_cap1

	function MenuLeft_Sub_TextBullet_cap2($parent_id, $file_default_link="", $css_link="")
	{
		global $subcatid, $langid;
		$file_link = "";
		$this->title = "";
		if ($file_default_link == ""){
			$file_default_link = "index.php";
		}
		$file_sanpham_link = "content.php";
		if($css_link == ""){
			$css_link = "menusub_left_2";
		}
		$css_nolink = $css_link."_nolink";
		$css_header = $css_link."_header";
		
		$td_height = "25";
		$td_width = "20";
		$title = "";
		$img_bullet = "&nbsp;";
		$td_bullet = "<td width='$td_width' align='center' valign='baseline' class='$css_nolink'>$img_bullet</td>";
		//$td_bullet = "";
		$td_line = "<TD height=1 bgcolor='#FFAF04' colspan='2'></TD>";
		$tr_line = "<TR>$td_line</TR>";
		
		
		//===========================================================================
		//Left Menu 
		$list_left = '';
			
		$list_content_nolink = "			
			<TR>
			$td_bullet
			<TD height='$td_height' align='left' class='$css_nolink'>@cat_name@</TD>
			</TR>
		";
		$list_content_link_nosubmenu = "			
			<TR>
			 $td_bullet				
			 <TD width='92%' height='$td_height' align='left' class='$css_nolink'>
			 <A  href='@file_link@?catid=@catid@&subcatid=@subcatid@&langid=@langid@' class='$css_link'>@cat_name@</A>
			</TD>
			</TR>
		";		
		$list_content_link = "			
			<TR>
			 $td_bullet				
			 <TD width='92%' height='$td_height' align='left' class='$css_nolink'>
			 <a class=\"$css_link\" href=\"#\">@cat_name@</a>
			</TD>
			</TR>
		";
		
		$list_content_menulink_3 = "			
			<TR>
			$td_bullet				
			 <TD height='$td_height' align='left' class='$css_header'>
			 @cat_name@
			</TD>
			</TR>
		";
		
		
		$sql_list="SELECT * FROM contents WHERE langid='$langid' and contents_parent='$parent_id' order by contents_order";
		//echo "sql_list: $sql_list<br>";
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		//$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{
			if ($i > 0 && $i < $num_row){
				$line = $tr_line;
			}else{
				$line = "";
			}
			$fld_id = $stmt->row["catid"];
			//echo "fld_id: $fld_id<br>";
			$menu_link = $stmt->row["cat_menu"];
			$target = $stmt->row["cat_pic1"];
			//echo "target: $target<br>";
			if($target == "_blank") {
				$target="target='_blank'";
			}else{
				$target="";
			}
			$cat_type = $stmt->row["cat_type"];
			switch ($cat_type){
				case 0:
					//echo "cattype=0<br>";
					$file_link = $file_default_link;
					break;
				case 1:
					//echo "cattype=1<br>";
					$file_link = $file_sanpham_link;
					break;
			}

			if ($subcatid == $fld_id)
			{
				$content=$line.$list_content_nolink;
				$this->title = $stmt->row["cat_name"];
				//echo "catid: $fld_id title: $this->title<br>";
			}
			else
			{		
				$submenu_no = get_values("SELECT count(*) as tong FROM contents where contents_parent='$fld_id'");
		
				if ($submenu_no == 0) //Khong co submenu
				{		
					if ($menu_link != "" || $menu_link != NULL){
						$content=$line.$list_content_menulink;
					}
					else{
						$content=$line.$list_content_link_nosubmenu; //template khong co submenu	
					}
				}
				else 
				{	//submenu cap 2
					$content=$line.$list_content_menulink_3;
					//echo "co submenu<br>";
					//echo "<pre>$content</pre>";	
				}						
			
			}
		
			$content=ereg_replace("@catid@","$parent_id",$content);
			$content=ereg_replace("@subcatid@",$stmt->row["contents_id"],$content);
			$content=ereg_replace("@cat_name@",$stmt->row["contents_name"],$content);
		
			$content=ereg_replace("@menuid@",$stmt->row["contents_id"],$content);
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			$content=ereg_replace("@target@",$target,$content);
			
			$content=ereg_replace("@langid@",$this->lang_id,$content);
			$content=ereg_replace("@file_link@", "$file_link",$content);
			
			//print "result:<br><pre>".htmlspecialchars($content, ENT_QUOTES)."</pre>"; //debug
			
			$list_left.= $content;
			$i++;
		}
		
		
		$list_menu = $list_left;
		
		return $list_menu;		
	}	//end function SubMenuBar_TextBullet_cap2	
	
	function Get_Subcatid($id)
	{
		$sql = "select contents_id from contents where contents_parent = '".$id."' order by contents_order limit 0,1";
		$subcatid = get_values($sql);
		if ($subcatid == "") $subcatid = "0";
		//echo "subcatid: $subcatid<br>";
		return $subcatid;
	} //end function Get_Subcatid
	
	function Get_ParentID($rootid, $id)
	{

		$sql = "select contents_parent from contents where contents_id='".$id."'";
		$id_ = get_values($sql);	
		//echo "rootid: $rootid - id: $id<br>";	
		if ($rootid != $id && $id > 0)
		{
			$parentid = $this->Get_ParentID($rootid, $id_);
			//echo "parentid: $parentid<br>";
		}
		
		return $id_;
		
		
	}//end Get_ParentID	
	
	function MenuLeft_Phancap_WriteToFile($parentid)
	{
		global $dbconn, $langid, $subcatid;

		$list_menu_all = "";
		$list_menu = "";
		$file_link = "index.php";
		$list_menu_begin = "";
		$list_menu_end = "";
		$list_menu_write = "";
		$list_submenu = "";
		
		
		$temp_list_begin = "\n\n\t window.myMenu@top_parent@ = new Menu(); \n";
		$temp_list_link = "\t myMenu@top_parent@.addMenuItem(\"@cat_name@\", \"top.window.location='$file_link?catid=$parentid&subcatid=@subcatid@&langid=@langid@'\"); \n";
		$temp_list_style = "
		\t //Thuoc tinh myMenu@top_parent@
		\t myMenu@top_parent@.menuItemBgColor = \"@menuItemBgColor@\";
		\t myMenu@top_parent@.menuHiliteBgColor = \"@menuHiliteBgColor@\";
		\t myMenu@top_parent@.fontColor = \"@fontColor@\";
		\t myMenu@top_parent@.bgColor = \"@bgColor@\";
		";
		$temp_list_write = "
		\t //xuat menu myMenu@top_parent@
		\t myMenu@top_parent@.writeMenus();	
		";
		
		$temp_submenu_begin = "\n\n\t window.mySubMenu@cat_parent@ = new Menu(\"@cat_name@\"); \n";
		$temp_submenu_list_link = "\t mySubMenu@cat_parent@.addMenuItem(\"@cat_name@\", \"top.window.location='$file_link?catid=$parentid&subcatid=@subcatid@&langid=@langid@'\"); \n";
		$temp_submenu_style = "
		\t //Thuoc tinh mySubMenu@cat_parent@
		\t mySubMenu@cat_parent@.menuItemBgColor = \"@menuItemBgColor@\";
		\t mySubMenu@cat_parent@.menuHiliteBgColor = \"@menuHiliteBgColor@\";
		\t mySubMenu@cat_parent@.fontColor = \"@fontColor@\";
		\t mySubMenu@cat_parent@.bgColor = \"@bgColor@\";
		";
		$temp_submenu = "\t myMenu@top_parent@.addMenuItem(mySubMenu@cat_parent@); \n";	
		
		//========================== Lap trinh tai day ================
		//=============================================================
		
		$sql_all = "SELECT * FROM cat WHERE cat_parent='".$parentid."' and enable=1 order by cat_order";
				
		
		//Kiem tra xem co bao nhieu top_parent (co submenu)
		//$top_parent_no = get_values("SELECT count(*) as tong FROM cat where cat_parent=104");
		$stmt_parent= new db_query($dbconn,$sql_all);
		$top_parent_no = 0;
		while ($stmt_parent->getrow())
		{
			$top_parent_id = $stmt_parent->row["catid"];
			$sql_parent_num = "SELECT count(*) as tong FROM cat where cat_parent=$top_parent_id";
			//echo "sql_parent_num:$sql_parent_num<br>";
			$top_parent_num = get_values($sql_parent_num);
			if ($top_parent_num > 0) {
				$top_parent_no++;
			}
		}
		
		
		$stmt_all= new db_query($dbconn,$sql_all);
		$stt=0;
		while ($stmt_all->getrow())
		{
		
			
			//Bat dau vong lap, se lay cac top_parent ===========================================
			$top_parent = $stmt_all->row["catid"];
			//echo "top_parent:$top_parent<br>";
			
			$sql_parent_num = "SELECT count(*) as tong FROM cat where cat_parent=$top_parent";
			//echo "sql_parent_num:$sql_parent_num<br>";
			$top_parent_num = get_values($sql_parent_num);
			if ($top_parent_num > 0) {
				$stt++;//tang bien dem
				//echo "stt: $stt - top_parent_no: $top_parent_no <br>";
			}
			
			$sql_list="SELECT * FROM cat WHERE cat_parent=$top_parent and enable=1 order by cat_order ";
			//echo "sql_list: $sql_list<br>";
			$stmt= new db_query($dbconn,$sql_list);	
			while ($stmt->getrow())
			{
				//Vong lap con ===============================================
				//============================================================
				//echo "Vong lap con<br>";
				$fld_id = $stmt->row["catid"];
				if ($subcatid == $fld_id)
				{
					$this->title = $stmt->row["cat_name"];
					$content=$temp_list_link;
					//echo "title_inc_menu_left=$title<br>";//debug
				}
				else
				{
							
					//Khoi tao bien Menu
					$list_menu_begin = $temp_list_begin;
					$list_menu_begin = ereg_replace("@top_parent@",$top_parent,$list_menu_begin);
					//style
					$list_menu_end = $temp_list_style;
					$list_menu_end = ereg_replace("@top_parent@",$top_parent,$list_menu_end);
				
					//Only write menu at END
					
					if($stt==$top_parent_no){
						//Write Menu
						$list_menu_write = $temp_list_write;
						$list_menu_write = ereg_replace("@top_parent@",$top_parent,$list_menu_write);
						//echo "stt=top_parent_no=$stt : $top_parent<br>";
					}
							
					//Kiem tra xem co submenu khong	
					$submenu_no = get_values("SELECT count(*) as tong FROM cat where cat_parent='$fld_id'");
					if ($submenu_no == 0) //Khong co submenu
					{
						//echo "Khong co submenu: $fld_id<br>";//debug
		
			
						$content=$temp_list_link; //template khong co submenu
						
						//echo "<pre>$content</pre>";
			
					}
					else
					{
						//echo "Co submenu: $fld_id<br>";						
						
						$content=$temp_submenu;	//template co submenu
						
						//echo "<pre>$content</pre>";
						
						//=========== Sub Menu ==================
						//Khoi tao bien Menu
						$list_submenu_begin = $temp_submenu_begin; 
						$list_submenu_begin = ereg_replace("@cat_parent@",$fld_id,$list_submenu_begin);
						$list_submenu_begin = ereg_replace("@cat_name@",$stmt->row["cat_name"],$list_submenu_begin);
						//style
						$list_submenu_end = $temp_submenu_style;
						$list_submenu_end = ereg_replace("@cat_parent@",$fld_id,$list_submenu_end);
						
						$list_submenu.= $list_submenu_begin;
						
						$sql_list_sub = "SELECT * FROM cat where cat_parent='$fld_id' order by cat_order";
						$stmt_sub= new db_query($dbconn,$sql_list_sub);
						while ($stmt_sub->getrow())
						{
							 
							$sub_subcatid = $stmt_sub->row["catid"];								
							if ($sub_subcatid == $subcatid) {
								$this->title = $stmt_sub->row["cat_name"];}
			
							$submenu = $temp_submenu_list_link;
							
							$submenu = ereg_replace("@subcatid@", "$subcatid", $submenu);
							$submenu = ereg_replace("@cat_name@",$stmt_sub->row["cat_name"],$submenu);
							$submenu = ereg_replace("@cat_parent@",$stmt_sub->row["cat_parent"],$submenu);
							$list_submenu.= $submenu;
							
							//echo "&nbsp;&nbsp;&nbsp;Sub Menu - List: $subcatid<br>";				
						}			
						$list_submenu.= $list_submenu_end;
						//echo "<pre>$list_submenu</pre>";
								
					}
				}
				
				//$content=$temp_list_link;
				$content=ereg_replace("@subcatid@",$stmt->row["catid"],$content);
				$content=ereg_replace("@cat_name@",$stmt->row["cat_name"],$content);
				$content=ereg_replace("@cat_parent@",$stmt->row["catid"],$content);
				$content=ereg_replace("@top_parent@",$top_parent,$content);
				
				
				$list_menu.= $content;
						
			}
			
			$list_menu = $list_menu_begin.$list_menu.$list_menu_end.$list_menu_write;
			$list_menu_all.=$list_submenu.$list_menu;
			
			//echo "<b>list_menu $top_parent</b>:<br><pre>$list_menu</pre>";
			
			//Khoi tao
			$list_menu_begin="";
			$list_menu_end="";
			$list_menu_write="";
			$list_submenu="";
			$list_menu="";
			
		
		} //Het vong lap lay top_parent
		$list_menu_all = ereg_replace("@langid@","$langid",$list_menu_all);
		$list_menu_all.="//hello";
		//echo "<b>Ketqua</b>:<br><pre>$list_menu_all</pre>";
		
		return $list_menu_all;
	}//end function MenuLeft_Phancap


	function MenuLeft_TextBullet($parent_id=0, $file_default_link="", $css_link="")
	{
		global $catid, $langid;
		
		$file_link = "";
		if($css_link == ""){
			$css_link = "menu_left";
		}
		$css_nolink = $css_link."_nolink";
		
		$td_height = "25";
		$td_width = "22";
		$title = "";
		$img_bullet = "<img src='../images_layout/left_bullet.gif'>";
		$td_bullet = "<td width='$td_width' align='center'  class='menuleft_sub'>$img_bullet</td>";
		//$td_bullet = "";
		//$td_line = "<TD height=1 bgcolor=#B9B9B9 colspan='2' onMouseOver=\"window.hideActiveMenus();\"></TD>";
		$td_line = "<TD height=1 colspan='2'><img src='../images_layout/left_line.gif'></TD>";		
		$tr_line = "<TR>$td_line</TR>";
		
		
		//===========================================================================
		//Left Menu 
		$list_left = '<TABLE width="100%" border=0 cellpadding="0" cellspacing="0"  align="left" > ';
			
		$list_content_nolink = "
			
			<TR>
			$td_bullet
			<TD height='$td_height' align='left' class='$css_nolink'>@cat_name@</TD>
			</TR>
		";
		$list_content_link = "			
			<TR>
			 $td_bullet				
			 <TD width='92%' height='$td_height' align='left' >
			 <A  href='@file_link@?catid=@catid@&langid=@langid@' class='$css_link'>@cat_name@</A>
			</TD>
			</TR>
		";		

				
		$sql_list="SELECT * FROM contents WHERE langid='$langid' order by contents_order";
		//echo "sql_list: $sql_list<br>";
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{
			if ($i > 0 && $i < $num_row){
				$line = $tr_line;
			}else{
				$line = "";
			}
			$fld_id = $stmt->row["contents_id"];
			$cat_type = $stmt->row["cat_type"];
			$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
			$file_link = get_values($sql_cat_type);				
			//echo "fld_id: $fld_id<br>";
			if ($catid == $fld_id){
				$content=$line.$list_content_nolink;
			}else{			
				$content=$line.$list_content_link;
			}
		
			$content=ereg_replace("@catid@","$fld_id",$content);
			$content=ereg_replace("@cat_name@",$stmt->row["contents_name"],$content);		
			$content=ereg_replace("@langid@",$this->lang_id,$content);
			$content=ereg_replace("@file_link@", "$file_link",$content);
			
			//print "result:<br><pre>".htmlspecialchars($content, ENT_QUOTES)."</pre>"; //debug
			
			$list_left.= $content;
			$i++;
		}
		
		$list_left.= $tr_line."   
		</TABLE>";
		
		
		$list_menu = $list_left;
		
		return $list_menu;		
	}	//end function MenuLeft_TextBullet


	function MenuLeft_TextBullet_ncap_0($parent_id, $css_link="")
	{
		global $subcatid, $catid, $arr_menu_id, $langid;
		$file_link = "";

		if ($file_default_link == ""){
			$file_default_link = "index.php";
		}
		$file_sanpham_link = "content.php";
		if($css_link == ""){
			$css_link = "menu_left";
		}
		$css_nolink = $css_link."_nolink";
		$css_header = "menu_left_top";
		//$css_header = "left_head";
		
		$td_height = "32";
		//$td_width = "180";
		//$width = "width = $td_width";
		
		$background = "background='../images_layout/menu_head.gif'";
		//$background_submenu = "background='../images_layout/left_center.gif'";
		//$background = "";
		
		$title = "";
		$img_bullet = "<img src='../images_layout/left_bullet.gif'>";	
		//$td_bullet = "<td align='center' >$img_bullet</td>";
		$td_bullet = "";
		//$td_line = "<TD height=1 bgcolor=#003660 colspan='2' ></TD>";
		//$td_line_2 = "<TD height=1 bgcolor=#ffffff colspan='2' ></TD>";
		//$td_line = "<TD height=1 colspan='2' ><img src='../images_layout/left_line.gif'></TD>";		
		//$td_line = "<TD height=14 ><img src='../images_layout/menu_end.gif'></TD>";
		$td_line = "<TD height=0></TD>";
		//$tr_line = "<TR>$td_line</TR><TR>$td_line_2</TR>";
		$tr_line = "<TR>$td_line</TR>";
		
		
		//===========================================================================
		//Left Menu 
		$list_left = '<TABLE width="168" border=0  cellpadding="0" cellspacing="0"  align="left" > ';
		
		$list_content_nolink = "			
			<TR>
			$td_bullet
			<TD $width height='$td_height' align='left' class='$css_nolink'>@cat_name@</TD>
			</TR>
			$tr_line
		";
		$list_content_link_nosubmenu = "			
			<TR> 
			$td_bullet								
			<TD $width height='$td_height' align='left' $background class='$css_header'>@cat_name@</TD>
			</TR>
			$tr_line
		";		


		$list_content_link_head = "
			<TR> 
				$td_bullet
				<TD $width height='$td_height' align='left' $background class='$css_header'>@cat_name@</TD>
			</TR>
			<tr>
				<td align=left $background_submenu>
				@list_menulink_1@
				</td>
			</tr>
			$tr_line
		";

		
		$list_content_menulink_1_select = $list_content_link_head;
	
		
		$sql_list="SELECT * FROM contents WHERE contents_parent='$parent_id' and langid='$langid' order by contents_order";
		//echo "sql_list: $sql_list<br>";
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{
			$fld_id = $stmt->row["contents_id"];
			//$menu_link = $stmt->row["cat_menu"];
			$cat_type = $stmt->row["cat_type"];
			$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
			$file_link = get_values($sql_cat_type);	
			//echo "$fld_id - $file_link - $sql_cat_type <br>";			
			$ten = $stmt->row["contents_name"];
			//$link = "cat.php?catid=$fld_id&id=$fld_id&langid=$langid";
			$link = "$file_link?catid=$fld_id&langid=$langid";
			$ten_link = "<a class='menu_left_top_link' href='$link'>$ten</a>";
			if ($subcatid == $fld_id)
			{
				$content=$line.$list_content_nolink;
				$this->title = $stmt->row["cat_name"];
				//echo "catid: $fld_id title: $this->title<br>";
			}
			else
			{		
				$submenu_no = get_values("SELECT count(*) as tong FROM contents where contents_parent='$fld_id'");
				//echo "submenu_no: $submenu_no<br>";
		
				if ($submenu_no == 0) //Khong co submenu
				{		
					if ($menu_link != "" || $menu_link != NULL){
						$content=$line.$list_content_menulink;
					}
					else{
						$content=$line.$list_content_link_nosubmenu; //template khong co submenu	
					}
				}
				else 
				{	//submenu cap 1
					//echo "catid: $catid<br>";
					$ten_link = $ten;
					$root_parent_id = $this->Get_ParentID(0, $catid);
					//echo "root_parent_id: $root_parent_id<br>";
					if ($catid == $stmt->row["contents_id"]){
						$content = $line.$list_content_menulink_1_select;
					}elseif($root_parent_id ==  $stmt->row["contents_id"]){
						$content = $line.$list_content_menulink_1_select;
					}else{
						$content = $line.$list_content_link_head;
					}
					$content = ereg_replace("@list_menulink_1@", $this->MenuLeft_TextBullet_ncap($fld_id), $content);
					//echo "co submenu fld_id: $fld_id<br>";
					//echo "<pre>$content</pre>";	
				}						
			
			}
		
			$content=ereg_replace("@catid@","$parent_id",$content);
			$content=ereg_replace("@subcatid@",$stmt->row["contents_id"],$content);
			//$content=ereg_replace("@cat_name@",$stmt->row["contents_name"],$content);
			$content=ereg_replace("@cat_name@","$ten_link",$content);
		
			$content=ereg_replace("@menuid@",$stmt->row["contents_id"],$content);
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			$content=ereg_replace("@target@",$target,$content);
			
			$content=ereg_replace("@langid@",$this->lang_id,$content);
			$content=ereg_replace("@file_link@", "$file_link",$content);
			
			//print "result:<br><pre>".htmlspecialchars($content, ENT_QUOTES)."</pre>"; //debug
			
			$list_left.= $content;
			$i++;
		}
		
		$list_left.= "   
		</TABLE>";
		
		
		$list_menu = $list_left;
		
		return $list_menu;		
	}	//end function MenuLeft_TextBullet_ncap_0

	function MenuLeft_TextBullet_ncap($parent_id, $css_link="")
	{
		global $subcatid, $catid, $arr_menu_id, $langid;
		$file_link = "";

		if ($file_default_link == ""){
			$file_default_link = "index.php";
		}
		$file_sanpham_link = "content.php";
		if($css_link == ""){
			$css_link = "menu_left";
		}
		$css_nolink = $css_link."_nolink";
		$css_header = $css_link."_header";
		//$css_header = "left_head";
		
		$td_height = "25";
		$td_width = "230";
		$width = "width = $td_width";
		
		//$background = "background='../images_layout/menu_left_head.gif'";
		$background = "";
		
		$title = "";
		$img_bullet = "<img src='../images_layout/bullet_1.gif'>";	
		$td_bullet = "<td align='center' >$img_bullet</td>";
		//$td_bullet = "";
		//$td_line = "<TD height=1 bgcolor=#003660 colspan='2' ></TD>";
		//$td_line_2 = "<TD height=1 bgcolor=#ffffff colspan='2' ></TD>";
		//$td_line = "<TD height=1 colspan='2' ><img src='../images_layout/left_line.gif'></TD>";		
		$td_line = "<TD height=1 colspan='2' ><img src='../images_layout/left_line.gif'></TD>";
		//$tr_line = "<TR>$td_line</TR><TR>$td_line_2</TR>";
		$tr_line = "<TR>$td_line</TR>";
		
		
		//===========================================================================
		//Left Menu 
		$list_left = '<TABLE width="100%" border=0 cellpadding="0" cellspacing="0"  align="center" > ';
		
		$list_content_nolink = "
			
			<TR>
			$td_bullet
			<TD $width height='$td_height' align='left' class='$css_nolink'>@cat_name@</TD>
			</TR>
		";
		$list_content_link_nosubmenu = "			
			<TR>
			 $td_bullet			
			 <TD $width height='$td_height' align='left' class='$css_header' $background>
			 <A  href='@file_link@?catid=@catid@&subcatid=@subcatid@&langid=@langid@' class='$css_link'>@cat_name@</A>
			</TD>
			</TR>
		";		
		
		$list_content_menulink = "
 			<TR>
			 $td_bullet			
			 <TD $width height='$td_height' align='left' class='$css_header' $background>
			 <A  href='@menu_link@' target=_blank class='$css_link'>@cat_name@</A>
			</TD>
			</TR>
		";


		$list_content_link_1 = "
			
			<TR onMouseOver=\"showhide_left('submenu_@subcatid@')\" onMouseOut=\"showhide_left('submenu_@subcatid@')\"> 
			$td_bullet								
			 <TD $width height='$td_height' align='left' $background class='$css_header'>
			 @cat_name@
			 </TD>
			</TR>

		  <tr id=\"submenu_@subcatid@\" style=\"display: none;\" onMouseOver=\"showhide_left('submenu_@subcatid@')\" onMouseOut=\"showhide_left('submenu_@subcatid@')\">
			<td align=left colspan='2'>                        
			<table border=0 cellpadding=0 cellspacing=0 width='100%' align='center'>
			  <tbody>			
				@list_menulink_1@
			</tbody>
			</table>
			</td>
			</tr>
			
		";

		
		$list_content_link_1_select = "
			
			<TR > 
			$td_bullet								
			 <TD $width height='$td_height' align='left' $background  class='$css_header'>
			 @cat_name@
			 </TD>
			</TR>
$tr_line
		  <tr id=\"submenu_@subcatid@\" style=\"display:'';\" >
			<td align=left colspan='2'>         
			<table border=0 cellpadding=0 cellspacing=0 width='100%' align='center' >
			  <tbody>			
				@list_menulink_1@
			</tbody>
			</table>
			</td>
			</tr>
			
		";		
	
		
		
		$sql_list="SELECT * FROM contents WHERE contents_parent='$parent_id' and langid='$langid' order by contents_order";
		//echo "sql_list: $sql_list<br>";
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{

			if ($i > 0 && $i < $num_row){
				$line = $tr_line;
			}else{
				$line = "";
			}

			$fld_id = $stmt->row["contents_id"];
			$menu_link = $stmt->row["contents_url"];
			$cat_type = $stmt->row["cat_type"];
			$sql_cat_type = "select file_default from cat_type where id = '".$cat_type."'";
			$file_link = get_values($sql_cat_type);	
			//echo "$fld_id - $file_link - $sql_cat_type <br>";			

			if ($subcatid == $fld_id)
			{
				$content=$line.$list_content_nolink;
				$this->title = $stmt->row["cat_name"];
				//echo "catid: $fld_id title: $this->title<br>";
			}
			else
			{		
				$submenu_no = get_values("SELECT count(*) as tong FROM contents where contents_parent='$fld_id'");
				//echo "submenu_no: $submenu_no<br>";
		
				if ($submenu_no == 0) //Khong co submenu
				{		
					if ($menu_link != "" || $menu_link != NULL){
						$content=$line.$list_content_menulink;
					}
					else{
						$content=$line.$list_content_link_nosubmenu; //template khong co submenu	
					}
				}
				else 
				{	//submenu cap 1
					//echo "catid: $catid<br>";
					$root_parent_id = $this->Get_ParentID(0, $catid);
					//echo "root_parent_id: $root_parent_id<br>";
					if ($catid == $stmt->row["contents_id"]){
						$content = $line.$list_content_link_1_select;
					}elseif($root_parent_id ==  $stmt->row["contents_id"]){
						$content = $line.$list_content_link_1_select;
					}else{
						$content = $line.$list_content_link_1;
					}
					$content = ereg_replace("@list_menulink_1@", $this->MenuLeft_Sub_TextBullet_cap1($fld_id), $content);
					//echo "co submenu fld_id: $fld_id<br>";
					//echo "<pre>$content</pre>";	
				}						
			
			}
		
			$content=ereg_replace("@catid@","$parent_id",$content);
			$content=ereg_replace("@subcatid@",$stmt->row["contents_id"],$content);
			$content=ereg_replace("@cat_name@",$stmt->row["contents_name"],$content);
		
			$content=ereg_replace("@menuid@",$stmt->row["contents_id"],$content);
			$content=ereg_replace("@menu_link@",$menu_link,$content);
			$content=ereg_replace("@target@",$target,$content);
			
			$content=ereg_replace("@langid@",$this->lang_id,$content);
			$content=ereg_replace("@file_link@", "$file_link",$content);
			
			//print "result:<br><pre>".htmlspecialchars($content, ENT_QUOTES)."</pre>"; //debug
			
			$list_left.= $content;
			$i++;
		}
		
		$list_left.= "   
		</TABLE>";
		
		
		$list_menu = $list_left;
		
		return $list_menu;		
	}	//end function MenuLeft_TextBullet_ncap


	function MenuLeft_Header($parent_id)
	{		
		//===========================================================================
		//Left Menu 
		$list_submenu = "";
		$list_left = '
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		';
			
		$list_content_nolink = '
			  <tr>
				<td height="39" background="../images_layout/left_head.gif" >	
				<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
				  <tr>
					<td width="20">&nbsp;</td>
					<td class="left_head">@cat_name@</td>
				  </tr>
				</table>	
				</td>
			  </tr>
			  
			  <tr>
				<td valign="top">
				@submenu@	
				</td>
			  </tr>
		';
		$list_content_link_nosubmenu = '
			  <tr>
				<td height="39" background="../images_layout/left_head.gif" >	
				<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
				  <tr>
					<td width="20">&nbsp;</td>
					<td class="left_head">@cat_name@</td>
				  </tr>
				</table>	
				</td>
			  </tr>
		';
		
		
		$sql_list="SELECT * FROM cat WHERE enable=1 and cat_parent='$parent_id' order by cat_order";
		//echo "sql_list: $sql_list<br>";
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{
			$fld_id = $stmt->row["catid"];
			//echo "fld_id: $fld_id<br>";

			$submenu_no = get_values("SELECT count(*) as tong FROM cat where cat_parent='$fld_id'");
	
			if ($submenu_no == 0){//Khong co submenu
				$content = $list_content_link_nosubmenu; //template khong co submenu				
			}else{
				$content = $list_content_nolink;
				$list_submenu = $this->MenuLeft_TextBullet($fld_id);
				$content = ereg_replace("@submenu@", $list_submenu, $content);
			}
		
			$content=ereg_replace("@cat_name@",$stmt->row["cat_name"],$content);
		
					
			$list_left.= $content;
			$i++;
		}		
		$list_left.= $tr_line."   
		</TABLE>";		
		
		$list_menu = $list_left;
		
		return $list_menu;		
	}	//end function MenuLeft_Header



	function MenuLeft_Home($parent_id)
	{		
		//===========================================================================
		$td_height = 'height="20"';
		$list_submenu = "";		
		$list_left = '
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		';
			
		$list_content = '
			  <tr>
				<td width="15" '.$td_height.'><img src="images_home/bullet_home.gif" width="15" height="9" /></td>
				<td>@cat_name@</td>
			  </tr>			  
		';
		
		$sql_list="SELECT * FROM contents WHERE contents_parent='$parent_id' order by contents_order";
		//echo "sql_list: $sql_list<br>";
		
		$stmt= new db_query($this->dbcon,$sql_list);
		$i = 0;
		$num_row = $stmt->numrows();
		while ($stmt->getrow())
		{
			$cat_name = $stmt->row["contents_name"];
			$contents_url = $stmt->row["contents_url"];
			if($contents_url != ""){
				$url = '<a href="'.$contents_url.'" class="menu_home">'.$cat_name.'</a>';
			}else{
				$url = $cat_name;
			}
			
			$content = $list_content;
			$content=ereg_replace("@cat_name@", "$url",$content);
		
			$list_left.= $content;
			$i++;
		}		
		$list_left.= $tr_line."   
		</TABLE>";		
		
		$list_menu = $list_left;
		
		return $list_menu;		
	}	//end MenuLeft_Home

	function MenuRight_Text($parent_id)
	{
		global $dbconn, $catid, $subcatid;
		
		$list = "";
		$list_begin = '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
		$list_end = '</table>';
		
		$tmp_content = '
			  <tr>
				<td height="25" bgcolor="#ff0000" class="menu_right_header">@name@</td>
			  </tr>
			  <tr>
				<td>@menu_sub@</td>
			  </tr>		
		';

		$user_id = get_user_id();
		if($user_id != ""){
			$sql = "select * from contents where contents_parent='$parent_id' order by contents_order";
		}else{
			$sql = "select * from contents where contents_parent='$parent_id' and tieubieu='0' order by contents_order";
		}
		
		$rs = new db_query($dbconn, $sql);
		while($rs->getrow()){
			$id = $rs->row['contents_id'];
			$name = $rs->row['contents_name'];
			
			$body = $tmp_content;
			$body = ereg_replace("@name@", $name, $body);
			
			//submenu
			$menu_sub = $this->MenuRight_Text_Sub1($id);
			$body = ereg_replace("@menu_sub@", $menu_sub, $body);
			
			
			$list .= $body;
			
			
		}//end while
		$list = $list_begin.$list.$list_end;
		return $list;
		
	}//end MenuRight_Text
	
	function MenuRight_Text_Sub1($parent_id)
	{
		global $dbconn, $subcatid, $langid;
		
		$list = "";
		$list_begin = '
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		';
		$list_end = '</table>';
		$tmp_nolink = '
		  <tr>
			<td width="15" align="center"><img src="../images_layout/bullet_1.gif" /></td>
			<td height = "22" class="menu_left_nolink">@name@</td>
		  </tr>		
		';
		$tmp_link = '
		  <tr>
			<td width="15" align="center"><img src="../images_layout/bullet_1.gif"  /></td>
			<td height = "22"><a href="@file_link@catid=@catid@&subcatid=@subcatid@&langid=@langid@" class="menu_left">@name@</a></td>
		  </tr>
		';
		$tmp_menulink = '
		  <tr>
			<td width="15" align="center"><img src="../images_layout/bullet_1.gif"  /></td>
			<td height = "22"><a href="@menu_link@" class="menu_left">@name@</a></td>
		  </tr>
		';		
		
		$user_id = get_user_id();
		if ($user_id != ""){
			$sql = "select * from contents where contents_parent = '$parent_id' order by contents_order";
		}else{
			$sql = "select * from contents where contents_parent = '$parent_id' and tieubieu='0' order by contents_order";
		}
		
		$rs = new db_query($dbconn, $sql);
		while ($rs->getrow()){
			$id = $rs->row['contents_id'];
			$name = $rs->row['contents_name'];
			$menu_link = $rs->row['contents_url'];
			
			$cat_type = $rs->row['cat_type'];
			$file_link = get_values("select file_default from cat_type where id = '$cat_type'");
			if(strstr("$file_link","?")){
				//tim thay dau ?
				$file_link .= "&";
			}else{
				$file_link .= "?";
			}
			
			if ($subcatid == $id){
				$body = $tmp_nolink;
			}else{
				if($menu_link !=""){
					$body = $tmp_menulink;
				}else{
					$body = $tmp_link;
				}
			}
			
			//echo "id: $id - file: $file_link - menu_link: $menu_link<br>";
			$body = ereg_replace("@name@", $name, $body);
			$body = ereg_replace("@file_link@", $file_link, $body);
			$body = ereg_replace("@menu_link@", $menu_link, $body);
			$body = ereg_replace("@catid@", "$parent_id", $body);
			$body = ereg_replace("@subcatid@", "$id", $body);
			$body = ereg_replace("@langid@", "$langid", $body);
			$list .= $body;
			
		}//end while
		$list = $list_begin.$list.$list_end;
		return $list;
	}//end MenuRight_Text_Sub1
	
	function Menu_Bottom($parent_id)
	{
		global $dbconn, $catid, $langid;
		$title = "";
		$list = "";
		$list_menu = "";
		$list_begin = "";
			
		$list_content_nolink = "<span class='menu_bottom_nolink'>@cat_name@</span>";
			 
		$list_content_link = "<A href='index.php?catid=@catid@&langid=@langid@' class='menu_bottom'>@cat_name@</A>";
		$list_content_menulink = "<A href='@menu_link@' class='menu_bottom'>@cat_name@</A>";
		
		$list_line = "&nbsp;&nbsp;|&nbsp;&nbsp;";
		
		$list_end = "";
			  
			  
		$sql_list="SELECT * FROM cat WHERE enable='1' and cat_parent='$parent_id' order by cat_order";
		
		$stmt= new db_query($dbconn,$sql_list);
		$i=0;
		while ($stmt->getrow())
		{
			$fld_id = $stmt->row["catid"];
			$menu_link = $stmt->row["cat_menu"];
			//echo "catid:$fld_id  -  cat_menu: $menu_link <br>";//debug	
			if ($catid == $fld_id)
			{
				if ($i > 0 ){
					$content=$list_line.$list_content_nolink;	}
				else {
					$content=$list_content_nolink;}
				
				//$title = $stmt->row["cat_name"];
				$this->title = $stmt->row["cat_name"];
			}
			else
			{
				if ($i > 0 ){
						if ($menu_link != "" || $menu_link != NULL){
							$content=$list_line.$list_content_menulink;
						}else{
							$content=$list_line.$list_content_link;	}
					}
				else {
						if ($menu_link != "" || $menu_link != NULL){
							$content=$list_content_menulink;
						}else{
							$content=$list_content_link;	}
					}		
			}
			
			$i++;
		
		
			$content=ereg_replace("@catid@",$stmt->row["catid"],$content);
			$content=ereg_replace("@cat_name@",$stmt->row["cat_name"],$content);
			$content=ereg_replace("@cat_menu@",$stmt->row["cat_menu"],$content);	
		
			$content=ereg_replace("@menuid@",$stmt->row["catid"],$content);		
			$content=ereg_replace("@menu_link@",$menu_link,$content);	
			$content=ereg_replace("@langid@","$langid",$content);		
			
			$list.= $content;
		}
		$list_menu = $list_begin.$list.$list_end;	
		return $list_menu;
	}	
	function get_title()
	{
		global $catid, $subcatid;
		$id=0;
		//echo "catid: $catid - subcatid: $subcatid<br>";
		if ($subcatid > 0){
			$id = $subcatid;
		}else{
			$id = $catid;
		}
		$sql = "select contents_name from contents where contents_id='$id'";
		//echo "$sql<br>";
		$title = get_values($sql);
		//echo "title : $title<br>";
		$this->title = $title;
	}
	

}//end class menu

?>
